Skip to content

Commit

Permalink
triangulate on iterator, take flags
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotwoods committed Jun 8, 2014
1 parent 74a88d1 commit 8b3deb8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 25 deletions.
55 changes: 32 additions & 23 deletions src/ofxTriangulate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,47 @@ void ofxTriangulate::Triangulate(DataSet data, Camera camera, Projector projecto

mesh.clear();
float maxLength2=maxLength*maxLength;
ofVec3f xyz;

DataSet::const_iterator it;
for (it = data.begin(); it != data.end(); ++it) {
DataSet::const_iterator::reference r = *it;
if ((*it).active) {
ofVec2f camXY = r.getCameraXYNorm();
ofVec2f projXY = r.getProjectorXYNorm();

camXY = camera.undistortCoordinate(camXY);

Ray cray = camera.castCoordinate(camXY);
Ray pray = projector.castCoordinate(projXY);
Ray intersect = cray.intersect(pray);

const auto lengthSquared = intersect.getLengthSquared();
if (lengthSquared > maxLength2){
continue;
}
ofVec3f xyz = intersect.getMidpoint();

mesh.addVertex(xyz);

if (giveColor) {
mesh.addColor(ofFloatColor(projXY.x, projXY.y, 0.0f));
}

if (giveTexCoord) {
mesh.addTexCoord(camXY);
if(Triangulate(it, camera, projector, xyz, maxLength2)) {
mesh.addVertex(xyz);

if (giveColor) {
auto projNorm = (*it).getProjectorXYNorm();
mesh.addColor(ofFloatColor(projNorm.x, projNorm.y, 0.0f));
}

if (giveTexCoord) {
auto camXY = (*it).getCameraXY();
mesh.addTexCoord(camXY);
}

}
}
}
}

//--------
bool ofxTriangulate::Triangulate(ofxGraycode::DataSet::const_iterator& it, const ofxRay::Camera& camera, const ofxRay::Projector& projector, ofVec3f& worldResult, float maxLength2) {
ofVec2f camXY = (*it).getCameraXYNorm();
ofVec2f projXY = (*it).getProjectorXYNorm();

Ray cray = camera.castCoordinate(camXY);
Ray pray = projector.castCoordinate(projXY);
Ray intersect = cray.intersect(pray);

const auto lengthSquared = intersect.getLengthSquared();
if (lengthSquared > maxLength2) {
return false;
}
worldResult = intersect.getMidpoint();
return true;
}

//--------
bool ofxTriangulate::Triangulate(int cameraPixelIndex, int projectorPixelIndex, const ofxRay::Camera& camera, const ofxRay::Projector& projector, ofVec3f& worldXYZResult, float maxLength) {
const ofVec2f cameraCoordinate = camera.getCoordinateFromIndex(cameraPixelIndex);
Expand Down
7 changes: 5 additions & 2 deletions src/ofxTriangulate.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ class ofxTriangulate {

///1 x Camera, 1 x Projector. Triangulate an ofxGraycode::DataSet
static void Triangulate(ofxGraycode::DataSet, ofxRay::Camera, ofxRay::Projector, ofMesh & mesh, float maxLength = std::numeric_limits<float>::max(), bool giveColor=true, bool giveTexCoord=true);

///1 x Camera, 1 x Projector. Triangulate an individual point

///1 x Camera, 1 x Projector. Triangulate a point in a ofxGraycode::DataSet
static bool Triangulate(ofxGraycode::DataSet::const_iterator& it, const ofxRay::Camera&, const ofxRay::Projector&, ofVec3f& worldXYZResult, float maxLength2 = std::numeric_limits<float>::max());

///1 x Camera, 1 x Projector. Triangulate an individual point by index
static bool Triangulate(int cameraPixelIndex, int projectorPixelIndex, const ofxRay::Camera&, const ofxRay::Projector&, ofVec3f& worldXYZResult, float maxLength = std::numeric_limits<float>::max());

///2 x Camera. Triangulate a single point
Expand Down

0 comments on commit 8b3deb8

Please sign in to comment.