Skip to content

Commit

Permalink
Fix bug in PPM normal interpolation (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
csparker247 authored Oct 27, 2023
1 parent 2e745f1 commit 63aecd9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion core/src/BarycentricCoordinates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ auto vc::BarycentricNormalInterpolation(
const cv::Vec3d& nC) -> cv::Vec3d
{
return cv::normalize(
(1 - uvw[0] - uvw[1]) * nA + uvw[1] * nB + uvw[2] * nC);
uvw[0] * nA + uvw[1] * nB + (1. - uvw[0] - uvw[1]) * nC);
}

bool vc::CartesianPointIsInTriangle(
Expand Down
28 changes: 13 additions & 15 deletions utils/src/PPMToPointSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <boost/program_options.hpp>

#include "vc/core/filesystem.hpp"
#include "vc/core/io/OBJWriter.hpp"
#include "vc/core/io/MeshIO.hpp"
#include "vc/core/types/ITKMesh.hpp"
#include "vc/core/types/PerPixelMap.hpp"
#include "vc/core/util/String.hpp"
Expand All @@ -23,9 +23,9 @@ struct ROI {
};

// Converts ROI string to ROI struct
ROI ParseROI(const std::string& opt);
auto ParseROI(const std::string& opt) -> ROI;

int main(int argc, char* argv[])
auto main(int argc, char* argv[]) -> int
{
///// Parse the command line options /////
// All command line options
Expand All @@ -35,9 +35,9 @@ int main(int argc, char* argv[])
("help,h", "Show this message")
("ppm,p", po::value<std::string>()->required(), "Input PPM file")
("output-mesh,o", po::value<std::string>()->required(),
"Output OBJ mesh file")
"Output mesh file")
("roi", po::value<std::string>(), "String describing origin and width "
"and height of region-of-interest. Format: X+Y+WxH");
"and height of region-of-interest. Format: WxH+X+Y");

po::options_description all("Usage");
all.add(required);
Expand Down Expand Up @@ -93,25 +93,23 @@ int main(int argc, char* argv[])
}

auto id = mesh->GetNumberOfPoints();
auto pos = ppm.getAsPixelMap(y, x).pos;
mesh->SetPoint(id, pos.val);
auto pt = ppm.getAsPixelMap(y, x);
mesh->SetPoint(id, pt.pos.val);
mesh->SetPointData(id, pt.normal.val);
}
}

// Write the mesh
std::cout << "Write OBJ file..." << std::endl;
fs::path outputPath = parsed["output-mesh"].as<std::string>();
vc::io::OBJWriter writer;
writer.setPath(outputPath);
writer.setMesh(mesh);
writer.write();
vc::WriteMesh(outputPath, mesh);
}

// Convert ROI string to ROI struct
ROI ParseROI(const std::string& opt)
auto ParseROI(const std::string& opt) -> ROI
{
// Match against regex
std::regex roiRegex{"^[0-9]*\\+[0-9]*\\+[0-9]*x[0-9]*$"};
std::regex roiRegex{"^[0-9]*x[0-9]*\\+[0-9]*\\+[0-9]*$"};
if (!std::regex_match(opt.begin(), opt.end(), roiRegex)) {
std::cerr << "Cannot parse ROI: " << opt << std::endl;
exit(EXIT_FAILURE);
Expand All @@ -128,6 +126,6 @@ ROI ParseROI(const std::string& opt)
}

return {
std::stoull(strs[0]), std::stoull(strs[1]), std::stoull(strs[2]),
std::stoull(strs[3])};
std::stoull(strs[2]), std::stoull(strs[3]), std::stoull(strs[0]),
std::stoull(strs[1])};
}

0 comments on commit 63aecd9

Please sign in to comment.