Skip to content

Commit

Permalink
Made writeOBJ. Not working, currently not able to do Patch.getPointInd()
Browse files Browse the repository at this point in the history
  • Loading branch information
goldbergd0 committed Jul 16, 2014
1 parent 877694b commit 3f05755
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 12 deletions.
11 changes: 10 additions & 1 deletion aux/triangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ class Triangle{
T getv(const int& i)const;

std::vector<T> unwrap()const;


Triangle<T>& operator=(const Triangle<T>& t);

private:
T v0_;
T v1_;
Expand Down Expand Up @@ -92,4 +94,11 @@ std::vector<T> Triangle<T>::unwrap()const{
return outvec;
}

template<typename T>
Triangle<T>& Triangle<T>::operator=(const Triangle<T>& t){
for (int i=0;i<3;++i){
setv(i,t.getv(i));
}
return *this;
}
#endif
4 changes: 4 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ int main() {
std::cout << (width>-1) <<std::endl;
std::cout <<"Map Global UV: ";
std::cout << w.mapGlobalUV(width)<<std::endl;
std::cout <<"Make Texture Mesh: ";
std::cout << w.makeTextureMesh()<<std::endl;
std::cout <<"Write obj File: ";
std::cout << w.writeOBJ()<<std::endl;

/*
std::vector<Camera> cams = w.getCameras();
Expand Down
44 changes: 34 additions & 10 deletions world/world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,6 @@ bool World::readPatchInfo(const std::string& fpath){
patches_[pointIndex].setNImages(numImg);
patches_[pointIndex].setInds(inds);
patches_[pointIndex].setPointInd(pointIndex);

// VERBOSE std::cout<<patchi<<": "<<p<<"\n";
}
}

Expand Down Expand Up @@ -306,9 +304,10 @@ bool World::buildTriangles(){

std::vector<pcl::Vertices>verts(mesh_.polygons);
Patch p;
size_t patchIndex;
for (size_t i=0; i<verts.size(); i++){
for (int ii=0;ii<3;ii++){
p = findPatch(verts[i].vertices[ii]);
p = patches_[patchIndex];
triangles_[i].setv(ii,p);
}
printPct(i,verts.size());
Expand Down Expand Up @@ -435,17 +434,42 @@ bool World::makeTextureMesh(){
texMat.tex_illum = 2;
tm.setTextureMaterials(texMat);

std::vector<std::string> texFiles;
texFiles.push_back("./textureAtlas.png");
tm.setTextureFiles(texFiles);

std::string texFile("./texture_atlas.png");
// tm.setTextureFiles(texFiles);
size_t numTriangles(triangles_.size());
texMesh_.header = mesh_.header;
texMesh_.cloud = mesh_.cloud;
texMesh_.tex_polygons.push_back( mesh_.polygons );


std::vector<Eigen::Vector2f> texCoord(numTriangles*3);
std::vector<pcl::Vertices> polygons(numTriangles);
pcl::Vertices vert;
Triangle<Patch> t;
Patch p;
for (size_t triInd=0;triInd<numTriangles;++triInd){
for (int vertInd=0;vertInd<3;++vertInd){
t = triangles_[triInd];
p = t.getv(vertInd);
std::cout<<p<<std::endl;
std::cout<<p.getPointInd()<<std::endl;
vert.vertices[vertInd] = p.getPointInd();
texCoord[triInd*3+vertInd] = uvg_[triInd].getv(vertInd);
}
polygons[triInd] = vert;
}
texMesh_.tex_polygons.push_back( polygons );

texMat.tex_name = "material_0";
texMat.tex_file = texFile;
texMesh_.tex_materials.push_back(texMat);

texMesh_.tex_coordinates.push_back(texCoord);

return false;
return true;
}

int World::writeOBJ(){
int status = pcl::io::saveOBJFile("./out.obj", texMesh_);
return status;
}

bool World::mapGlobalUV(const int& imWidth){
Expand Down
3 changes: 2 additions & 1 deletion world/world.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
//#include <pcl/io/vtk_lib_io.h>
//#include <pcl/io/ply.h>
#include <pcl/io/ply_io.h>
#include <pcl/io/obj_io.h>
#include <pcl/point_cloud.h>
#include <pcl/PolygonMesh.h>
#include <pcl/kdtree/kdtree_flann.h>
Expand Down Expand Up @@ -72,7 +73,7 @@ class World{
bool mapLocalUV();
int makeTextureAtlas();
bool makeTextureMesh();
bool writeOBJ();
int writeOBJ();

bool mapGlobalUV(const int& imWidth);
cv::Mat createOneImage(const std::vector<cv::Mat>& images,int& imWidth)const;
Expand Down

0 comments on commit 3f05755

Please sign in to comment.