void VRMeshEditor::centerDisplayCallback(Misc::CallbackData* cbData) { /* Calculate bounding box of current mesh: */ Vrui::Point bbMin,bbMax; MyVIt vIt=mesh->beginVertices(); for(int i=0; i<3; ++i) bbMin[i]=bbMax[i]=(*vIt)[i]; for(++vIt; vIt!=mesh->endVertices(); ++vIt) { for(int i=0; i<3; ++i) { if(bbMin[i]>(*vIt)[i]) bbMin[i]=(*vIt)[i]; else if(bbMax[i]<(*vIt)[i]) bbMax[i]=(*vIt)[i]; } } Vrui::Point modelCenter=Geometry::mid(bbMin,bbMax); Vrui::Scalar modelSize=Geometry::dist(modelCenter,bbMax); /* Calculate navigation transformation: */ Vrui::NavTransform t=Vrui::NavTransform::translateFromOriginTo(Vrui::getDisplayCenter()); t*=Vrui::NavTransform::scale(Vrui::Scalar(0.5)*Vrui::getDisplaySize()/modelSize); t*=Vrui::NavTransform::translateToOriginFrom(modelCenter); Vrui::setNavigationTransformation(t); }
void KnotsViewer::draw_curvature_error_domain() { if(surfacedata==NULL) return; if ((surfacedata->get_domain()).empty()) return; MyMesh polymesh = surfacedata->get_polymesh(); if (polymesh.edges_empty()==true) return; MyMesh::ConstFaceIter f_it(polymesh.faces_begin()),f_end(polymesh.faces_end()); MyMesh::ConstFaceVertexIter fv_it; //glLineWidth(0.5); for (; f_it!=f_end; ++f_it) { glColor3ubv(polymesh.color(*f_it).data()); glBegin(GL_POLYGON); fv_it = polymesh.cfv_iter(*f_it); glVertex3dv(&polymesh.point(fv_it)[0]); ++fv_it; glVertex3dv(&polymesh.point(fv_it)[0]); ++fv_it; glVertex3dv(&polymesh.point(fv_it)[0]); ++fv_it; glVertex3dv(&polymesh.point(fv_it)[0]); glEnd(); } }
void VRMeshEditor::createMorphBoxCallback(Misc::CallbackData* cbData) { /* Delete the old morph box: */ if(morphBox!=0) { delete morphBox; morphBox=0; } /* Calculate bounding box of current mesh: */ MyMorphBox::Point bbMin,bbMax; MyVIt vIt=mesh->beginVertices(); for(int i=0; i<3; ++i) bbMin[i]=bbMax[i]=(*vIt)[i]; for(++vIt; vIt!=mesh->endVertices(); ++vIt) { for(int i=0; i<3; ++i) { if(bbMin[i]>(*vIt)[i]) bbMin[i]=(*vIt)[i]; else if(bbMax[i]<(*vIt)[i]) bbMax[i]=(*vIt)[i]; } } /* Create a new morph box: */ MyMorphBox::Scalar size[3]; for(int i=0; i<3; ++i) size[i]=bbMax[i]-bbMin[i]; morphBox=new MyMorphBox(mesh,bbMin,size); }
char* refine(int num) { MyMesh m; int t0=clock(); int loadmask; printf("Buffer ptr is '%i'\n",buf); printf("Buffer[0] is '%c'\n",buf[0]); int ret = tri::io::ImporterOFF<MyMesh>::OpenMem(m,buf,strlen(buf),loadmask); int t1=clock(); if(ret != 0) { printf("Error in opening file\n"); exit(-1); } int t2=clock(); printf("Read mesh %i %i\n",m.FN(),m.VN()); tri::UpdateTopology<MyMesh>::FaceFace(m); tri::EdgeLen<MyMesh,float> edgePred(0); tri::MidPoint<MyMesh> midFun(&m); tri::RefineE(m,midFun,edgePred); int t3=clock(); printf("Refined mesh %i %i\n",m.FN(),m.VN()); printf("Opening time %5.2f \n Refinement time %5.2f",float(t1-t0)/CLOCKS_PER_SEC,float(t3-t2)/CLOCKS_PER_SEC); char *bufMeshOut = tri::io::ExporterOFF<MyMesh>::SaveStream(m); return bufMeshOut; }
void computeCurvature(TriMesh *&triMesh, MyMesh**tMesh) { TriMesh *tmesh = new TriMesh(*triMesh); unsigned vNum = tmesh->vertices.size(); tmesh->colors.resize(triMesh->vertices.size()); colorbycurv(tmesh, "0.0", "0.1"); unsigned i = 0; double maxAnis = 0; MyMesh* myMesh = *tMesh; for (MyMesh::VertexIter v_it = myMesh->getVertices().begin(); v_it != myMesh->getVertices().end(); v_it++) { v_it->normal() = AML::double3(tmesh->normals[i][0], tmesh->normals[i][1], tmesh->normals[i][2]); v_it->color() = AML::double3(tmesh->colors[i][0], tmesh->colors[i][1], tmesh->colors[i][2]); v_it->direction(0) = AML::double3(tmesh->pdir1[i][0], tmesh->pdir1[i][1], tmesh->pdir1[i][2]); v_it->direction(1) = AML::double3(tmesh->pdir2[i][0], tmesh->pdir2[i][1], tmesh->pdir2[i][2]); v_it->magnitude(0) = fabs(tmesh->curv1[i]); v_it->magnitude(1) = fabs(tmesh->curv2[i]); double& k1 = v_it->magnitude(0); double& k2 = v_it->magnitude(1); double diff = fabs(k1 - k2); if (maxAnis < diff) { maxAnis = diff; } i++; } AnisGeodesic::maxAnis = maxAnis; delete tmesh; }
void drawMesh(int x, int y, int width, int height){ MyGraphicsTool::SetViewport(MyVec4i(x, y, width, height)); glPushMatrix(); { MyGraphicsTool::LoadTrackBall(&trackBall); MyGraphicsTool::Rotate(180, MyVec3f(0, 1, 0)); MyBoundingBox box = mesh.GetBoundingBox(); MyGraphicsTool::Translate(-box.GetCenter()); mesh.Render(); }glPopMatrix(); }
inline uintptr_t getFaceVector() { int * f = new int[m.FN()*3]; int k=0; for (int i = 0; i < m.FN(); i++) for (int j = 0; j < 3; j++){ f[k] = (int)tri::Index(m,m.face[i].cV(j)); k++; } return (uintptr_t)f; }
inline uintptr_t getVertexVector() { float * v = new float[m.VN()*3]; int k=0; for (int i = 0; i < m.VN(); i++){ for (int j = 0; j < 3; j++){ v[k] = m.vert[i].cP()[j]; k++; } } return (uintptr_t)v; }
void SmoothPlugin(uintptr_t _m, int step) { MyMesh *n = (MyMesh*) _m; int t2=clock(); tri::UpdateTopology<MyMesh>::VertexFace(*n); tri::Smooth<MyMesh>::VertexCoordLaplacian(*n, step, false, true); tri::UpdateNormal<MyMesh>::PerVertexPerFace(*n); int t3=clock(); printf("Smooth mesh %i vert - %i face \n",n->VN(),n->FN()); printf("Smooth time %5.2f\n",float(t3-t2)/CLOCKS_PER_SEC); }
int openMesh() { int loadmask; int ret = tri::io::ImporterOFF<MyMesh>::OpenMem(m,buf,strlen(buf),loadmask); if(ret != 0) { printf("Error in opening file\n"); exit(-1); } printf("Read mesh %i %i\n",m.FN(),m.VN()); return ret; }
int main( int argc, char **argv ) { if(argc<3) { printf("Usage trimesh_base <meshfilename> radius (as perc) (\n"); return -1; } MyMesh m; MyMesh subM; MyMesh cluM; MyMesh rndM; tri::MeshSampler<MyMesh> mps(subM); tri::MeshSampler<MyMesh> mrs(rndM); if(tri::io::Importer<MyMesh>::Open(m,argv[1])!=0) { printf("Error reading file %s\n",argv[1]); exit(0); } tri::SurfaceSampling<MyMesh,tri::TrivialSampler<MyMesh> >::SamplingRandomGenerator().initialize(time(0)); float perc = atof(argv[2]); float radius = m.bbox.Diag() * perc; printf("Subsampling a PointCloud of %i vert with %f radius\n",m.VN(),radius); tri::SurfaceSampling<MyMesh,tri::MeshSampler<MyMesh> >::PoissonDiskParam pp; tri::SurfaceSampling<MyMesh,tri::MeshSampler<MyMesh> >::PoissonDiskParam::Stat pds; pp.pds=&pds; pp.bestSampleChoiceFlag=false; tri::SurfaceSampling<MyMesh,tri::MeshSampler<MyMesh> >::PoissonDiskPruning(mps, m, radius, pp); tri::io::ExporterPLY<MyMesh>::Save(subM,"PoissonMesh.ply"); printf("Sampled %i vertices in %5.2f\n",subM.VN(), float(pds.pruneTime+pds.gridTime)/float(CLOCKS_PER_SEC)); int t0=clock(); tri::Clustering<MyMesh, vcg::tri::AverageColorCell<MyMesh> > ClusteringGrid; ClusteringGrid.Init(m.bbox,100000,radius*sqrt(2.0f)); ClusteringGrid.AddPointSet(m); ClusteringGrid.ExtractMesh(cluM); int t1=clock(); tri::io::ExporterPLY<MyMesh>::Save(cluM,"ClusterMesh.ply"); printf("Sampled %i vertices in %5.2f\n",cluM.VN(), float(t1-t0)/float(CLOCKS_PER_SEC)); int t2=clock(); int sampleNum = (cluM.VN()+subM.VN())/2; tri::SurfaceSampling<MyMesh,tri::MeshSampler<MyMesh> >::VertexUniform(m, mrs,sampleNum); int t3=clock(); tri::io::ExporterPLY<MyMesh>::Save(rndM,"RandomMesh.ply"); printf("Sampled %i vertices in %5.2f\n",rndM.VN(), float(t3-t2)/float(CLOCKS_PER_SEC)); return 0; }
void MyGL::setMesh(MyMesh mesh) { petal_mesh = mesh; points.clear(); //点 for (auto it = mesh.vertices_begin(); it != mesh.vertices_end(); ++it){ auto point = mesh.point(it.handle()); coor t = { point.data()[0], point.data()[1], point.data()[2] }; points.push_back(t); } //面 face.clear(); for (auto it = mesh.faces_begin(); it != mesh.faces_end(); ++it){ OpenMesh::FaceHandle fh = it.handle(); coor facet;//当前面索引 int count = 0;//标记第几个点 for (auto it1 = mesh.fv_begin(fh); it1 != mesh.fv_end(fh); ++it1){ auto point = mesh.point(it1.handle()); t = { point.data()[0], point.data()[1], point.data()[2] }; //find vector<coor>::iterator itv;//记录该点对应Points中的位置 itv = find_if(points.begin(), points.end(), [](coor const& obj){ return (fabs(obj.x - t.x) < 0.01) && (fabs(obj.y - t.y) < 0.01) && (fabs(obj.z - t.z) < 0.01); }); if (itv != points.end())//写入面facet { if (count == 0){ facet.x = itv - points.begin(); } else if (count == 1){ facet.y = itv - points.begin(); } else facet.z = itv - points.begin(); } else break; count++; } face.push_back(facet); } return; }
void mySmooth(int step) { int t2=clock(); tri::RequirePerVertexNormal(*n); tri::UpdateTopology<MyMesh>::VertexFace(*n); tri::Smooth<MyMesh>::VertexCoordLaplacian(*n, step, false, true); tri::UpdateNormal<MyMesh>::PerVertexPerFace(*n); int t3=clock(); printf("Smooth mesh %i vert - %i face \n",n->VN(),n->FN()); printf("Smooth time %5.2f\n",float(t3-t2)/CLOCKS_PER_SEC); }
bool Load(const char* filename, MyMesh& mesh) { //Create the data descriport for the custom attributes nanoply::NanoPlyWrapper<MyMesh>::CustomAttributeDescriptor customAttrib; customAttrib.GetMeshAttrib(filename); int count = customAttrib.meshAttribCnt["material"]; mesh.material().resize(count); customAttrib.AddVertexAttribDescriptor<int, int, 1>(std::string("materialId"), nanoply::NNP_INT32, NULL); customAttrib.AddFaceAttribDescriptor<vcg::Point3f, float, 3>(std::string("barycenter"), nanoply::NNP_LIST_UINT8_FLOAT32, NULL); customAttrib.AddMeshAttribDescriptor<Material, float, 3>(std::string("material"), std::string("kd"), nanoply::NNP_FLOAT32, mesh.material()[0].kd.V()); customAttrib.AddMeshAttribDescriptor<Material, float, 3>(std::string("material"), std::string("ks"), nanoply::NNP_FLOAT32, mesh.material()[0].ks.V()); customAttrib.AddMeshAttribDescriptor<Material, float, 1>(std::string("material"), std::string("rho"), nanoply::NNP_FLOAT32, &mesh.material()[0].rho); //Load the ply file unsigned int mask = 0; mask |= nanoply::NanoPlyWrapper<MyMesh>::IO_VERTCOORD; mask |= nanoply::NanoPlyWrapper<MyMesh>::IO_VERTNORMAL; mask |= nanoply::NanoPlyWrapper<MyMesh>::IO_VERTCOLOR; mask |= nanoply::NanoPlyWrapper<MyMesh>::IO_VERTRADIUS; mask |= nanoply::NanoPlyWrapper<MyMesh>::IO_VERTATTRIB; mask |= nanoply::NanoPlyWrapper<MyMesh>::IO_FACEINDEX; mask |= nanoply::NanoPlyWrapper<MyMesh>::IO_FACENORMAL; mask |= nanoply::NanoPlyWrapper<MyMesh>::IO_FACEATTRIB; mask |= nanoply::NanoPlyWrapper<MyMesh>::IO_MESHATTRIB; return (nanoply::NanoPlyWrapper<MyMesh>::LoadModel(filename, mesh, mask, customAttrib) != 0); }
void CapHole(MyMesh &m, MyMesh &capMesh, bool reverseFlag) { capMesh.Clear(); std::vector< std::vector<Point3f> > outlines; std::vector<Point3f> outline; tri::Allocator<MyMesh>::CompactVertexVector(m); tri::Allocator<MyMesh>::CompactFaceVector(m); tri::UpdateFlags<MyMesh>::FaceClearV(m); tri::UpdateFlags<MyMesh>::VertexClearV(m); tri::UpdateTopology<MyMesh>::FaceFace(m); int nv=0; for(size_t i=0; i<m.face.size(); i++) { for (int j=0; j<3; j++) if (!m.face[i].IsV() && face::IsBorder(m.face[i],j)) { MyFace* startB=&(m.face[i]); vcg::face::Pos<MyFace> p(startB,j); assert(p.IsBorder()); do { assert(p.IsManifold()); p.F()->SetV(); outline.push_back(p.V()->P()); p.NextB(); nv++; } while(!p.F()->IsV()); if (reverseFlag) std::reverse(outline.begin(),outline.end()); outlines.push_back(outline); outline.clear(); } } if (nv<2) return; MyMesh::VertexIterator vi=vcg::tri::Allocator<MyMesh>::AddVertices(capMesh,nv); for (size_t i=0; i<outlines.size(); i++) { for(size_t j=0; j<outlines[i].size(); ++j,++vi) (&*vi)->P()=outlines[i][j]; } std::vector<int> indices; glu_tesselator::tesselate(outlines, indices); std::vector<Point3f> points; glu_tesselator::unroll(outlines, points); MyMesh::FaceIterator fi=tri::Allocator<MyMesh>::AddFaces(capMesh,nv-2); for (size_t i=0; i<indices.size(); i+=3,++fi) { (*&fi)->V(0)=&capMesh.vert[ indices[i+0] ]; (*&fi)->V(1)=&capMesh.vert[ indices[i+1] ]; (*&fi)->V(2)=&capMesh.vert[ indices[i+2] ]; } tri::Clean<MyMesh>::RemoveDuplicateVertex(capMesh); tri::UpdateBounding<MyMesh>::Box(capMesh); }
int main(int argc, char* argv[]) { if (argc < 2){ return 0; } float meshPrecision = 0.01; MyMesh mesh; //mesh.Read(argv[1]); //mesh.MergeVertices(meshPrecision); //mesh.ClearNonRegularFaces(); //mesh.GenPerVertexNormal(); mesh.Read("data\\lh.pial.DK.fusiform_trans.obj"); //mesh.ReadAsc("data\\lh.pial.asc"); mesh.MergeVertices(meshPrecision); //mesh.RemoveVertex(MyArrayi(1, 40969)); mesh.GenPerVertexNormal(); mesh.Write("data\\lh.pial.DK.fusiform_trans_normal.obj"); //mesh.WriteNOFF("data\\lh.pial.off"); //mesh.WriteAsc("data\\lh.sphere_v163841.asc"); //mesh.WriteBIN("data\\lh.pial_v163841.bin"); //mesh.WriteNOFF("data\\lh_trans_pial_noff.off"); //mesh.WritePLY("data\\lh.pial.ply"); //mesh.WriteSMFD("data\\lh.trans.pial.smfd"); //MyTracks track; //track.Read("C:\\Users\\GuohaoZhang\\Desktop\\tmpdata\\dti.trk"); //track.Save("C:\\Users\\GuohaoZhang\\Desktop\\tmpdata\\dti.data"); /* MyTracks track; track.Read("C:\\Users\\GuohaoZhang\\Desktop\\tmpdata\\dti.trk"); vector<int> idx; for (int i = 0; i < track.GetNumTracks(); i++){ idx.push_back(i); } vector<int> filter1, filter2; float lengthLimit[] = { 20, FLT_MAX }; track.FilterByIndexSkip(idx, 0.99, filter1); cout << filter1.size() << endl; track.FilterByTrackLength(filter1, lengthLimit, filter2); cout << filter2.size() << endl; track.SavePartial("dti_20_099.data", filter2); */ }
void resetShaders(int mode){ #ifdef TRACK track.LoadShader(); glutPostRedisplay(); #endif #ifdef MESH mesh.CompileShader(); glutPostRedisplay(); #endif }
int main( int /*argc*/, char **/*argv*/ ) { MyMesh m; vcg::tri::Torus(m,30,10); vcg::tri::io::ExporterOFF<MyMesh>::Save(m,"torus.off"); vcg::tri::UpdateTopology<MyMesh>::FaceFace(m); // vcg::tri::UpdateCurvature<MyMesh>::VertexCurvature(m); vcg::tri::UpdateCurvature<MyMesh>::MeanAndGaussian(m); vcg::tri::UpdateCurvature<MyMesh>::PrincipalDirections(m); //vcg::tri::UpdateCurvature<MyMesh>::PrincipalDirectionsNormalCycles(m); vcg::tri::UpdateCurvature<MyMesh>::PrincipalDirectionsPCA(m,m.bbox.Diag()/100); vcg::tri::UpdateNormal<MyMesh>::PerVertexNormalized(m); printf("Input mesh vn:%i fn:%i\n",m.VN(),m.FN()); printf( "Mesh has %i vert and %i faces\n", m.VN(), m.FN() ); return 0; }
void initMesh( obj::ObjObject* pObj){ vector<obj::POINT>* pts = pObj->getPoints(); vector<obj::FACEINDEX>* fs = pObj->getFaces(); MyMesh::VertexHandle* vhandler = new MyMesh::VertexHandle[pts->size()]; for( size_t i = 0 ; i != pts->size() ; i++ ){ vhandler[i] = mesh.add_vertex( MyMesh::Point( (*pts)[ i ].x , (*pts)[ i ].y , (*pts)[ i ].z ) ); } vector<MyMesh::VertexHandle> face_handler; for( size_t i = 0 ; i != fs->size() ; i++ ){ face_handler.clear(); face_handler.push_back( vhandler[(*fs)[i].index[0]] ); face_handler.push_back( vhandler[(*fs)[i].index[1]] ); face_handler.push_back( vhandler[(*fs)[i].index[2]] ); mesh.add_face( face_handler ); } delete [] vhandler; }
/** This function is the main program executed to test that libMesh is * properly linked and that my custom fem library MyMesh class is * functioning correctly. * * The command-line arguments are parsed into the two input variables * of this program: * \param argc The command-line argument count * \param argv An array of characters that contain the command-line text, * this text is parsed with the initialization of libMesh */ int main(int argc, char** argv) { LibMeshInit init (argc, argv); MyMesh mesh; MeshTools::Generation::build_square(mesh, 3, 3); mesh.find_neighbors(); printf("\n\nBoundary id's generated by libMesh:\n"); mesh.boundary_info->print_info(); printf("\n\nBoundary id's generated by MyMesh class (+10):\n"); mesh.boundary_info->clear(); mesh.add_boundary_id(10,"y",0.); // bottom mesh.add_boundary_id(11,"x",1.); // right-side mesh.add_boundary_id(12,"y",1.); // top mesh.add_boundary_id(13,"x",0.); // left mesh.boundary_info->print_info(); }
/*Add random Gaussian Noise to verteices*/ void AddNoise(double noise_standard_deviation,MyMesh &mesh) { std::default_random_engine generator; std::normal_distribution<double> distribution(0.0,noise_standard_deviation); //Gaussian distribution: mean value = 0.0 for (auto it = mesh.vertices_begin(); it != mesh.vertices_end(); ++it) { double Pt[3] = {}; for (int d=0;d<3;d++) { Pt[d]=*(mesh.point(it).data()+d); double randn = distribution(generator); if ((randn>=-1.0)&&(randn<=1.0))//Gaussian distribution range [-1.0,1.0] { Pt[d]= Pt[d]*(1.0+randn); *(mesh.point(it).data()+d)=float(Pt[d]); } } } NOISE_CONTROL = false; }
void BoundingBox::calculateAll(const MyMesh &mesh) { MyMesh::ConstVertexIter v_it=mesh.vertices_begin(); minPoint.x = maxPoint.x = mesh.point(v_it)[0]; minPoint.y = maxPoint.y = mesh.point(v_it)[1]; minPoint.z = maxPoint.z = mesh.point(v_it)[2]; ++v_it; for (; v_it!=mesh.vertices_end(); ++v_it){ float x = mesh.point(v_it)[0]; float y = mesh.point(v_it)[1]; float z = mesh.point(v_it)[2]; if (x < minPoint.x) minPoint.x = x; if (x > maxPoint.x) maxPoint.x = x; if (y < minPoint.y) minPoint.y = y; if (y > maxPoint.y) maxPoint.y = y; if (z < minPoint.z) minPoint.z = z; if (z > maxPoint.z) maxPoint.z = z; } calcDiagonal(); calcCenterPoint(); }
void readTrimesh(MeshSegment*& meshSeg, const char* fileName) { std::vector<AML::double3> points; std::vector<std::vector<unsigned> > faces; TriMesh *triMesh = TriMesh::read(fileName); int vNum = triMesh->vertices.size(); points.reserve(vNum); for (int i = 0; i < vNum; i++) { points.push_back(AML::double3(triMesh->vertices[i][0], triMesh->vertices[i][1], triMesh->vertices[i][2])); } int fNum = triMesh->faces.size(); faces.reserve(fNum); std::vector<unsigned> tf(3); for (int i = 0; i < fNum; i++) { tf[0] = triMesh->faces[i][0]; tf[1] = triMesh->faces[i][1]; tf[2] = triMesh->faces[i][2]; faces.push_back(tf); } rescaleMesh(points); for (int i = 0; i < vNum; i++) { for (int j = 0; j < 3; j++) { triMesh->vertices[i][j] = points[i][j]; } } triMesh->need_normals(); MyMesh* tmesh = new MyMesh; tmesh->initialize(points, faces); *(meshSeg->getMyMesh()) = tmesh; computeCurvature(triMesh, meshSeg->getMyMesh()); }
int main( int argc, char **argv ) { if(argc<2) { printf("Usage trimesh_base <meshfilename.obj>\n"); return -1; } /*! */ MyMesh m; if(vcg::tri::io::ImporterOFF<MyMesh>::Open(m,argv[1])!=vcg::tri::io::ImporterOFF<MyMesh>::NoError) { printf("Error reading file %s\n",argv[1]); exit(0); } vcg::tri::RequirePerVertexNormal(m); vcg::tri::UpdateNormal<MyMesh>::PerVertexNormalized(m); printf("Input mesh vn:%i fn:%i\n",m.VN(),m.FN()); printf( "Mesh has %i vert and %i faces\n", m.VN(), m.FN() ); return 0; }
int getFaceNumber() { return m.FN(); }
int getVertexNumber() { return m.VN(); }
int main(int argc, char* argv[]) { /****************************************/ /* Initialize GLUT and create window */ /****************************************/ glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); glutInitWindowPosition(80, 80); glutInitWindowSize(windowWidth, windowHeight); int main_window = glutCreateWindow("Rendering Test"); glewInit(); glutDisplayFunc(myGlutDisplay); glutMotionFunc(myGlutMotion); glutReshapeFunc(myGlutReshape); glutPassiveMotionFunc(myGlutPassiveMotion); glutMouseWheelFunc(myGlutMouseWheel); glutMouseFunc(myGlutMouse); glutKeyboardFunc(myGlutKeyboard); glEnable(GL_DEPTH_TEST); /****************************************/ /* Here's the GLSL code */ /****************************************/ geomFb.AddExtraDrawTexture(GL_RGBA32F, GL_RGBA, GL_FLOAT, GL_NEAREST, GL_CLAMP_TO_EDGE); geomFb.AddExtraDrawTexture(GL_RGBA32F, GL_RGBA, GL_FLOAT, GL_NEAREST, GL_CLAMP_TO_EDGE); glClampColor(GL_CLAMP_READ_COLOR, GL_FALSE); glClampColor(GL_CLAMP_VERTEX_COLOR, GL_FALSE); glClampColor(GL_CLAMP_FRAGMENT_COLOR, GL_FALSE); /****************************************/ /* Loading Data */ /****************************************/ ssaoPass.Build(); blurPass.Build(); lightingPass.Build(); #ifdef TRACK trackBall.SetRotationMatrix(MyMatrixf::RotateMatrix(90, 1, 0, 0)); trackBall.ScaleMultiply(1.3); MyTracks tractData; MyBitmap bitmap; bitmap.Open("..\\SSAO\\data\\diverging.bmp"); gTex = MyTexture::MakeGLTexture(&bitmap); //tractData.Read("data\\normal_s3.data"); tractData.Read("C:\\Users\\GuohaoZhang\\Dropbox\\data\\normal_s4.tensorinfo"); tractData.AppendTrackColor("C:\\Users\\GuohaoZhang\\Dropbox\\data\\normal_s4_boy.data"); tractData.Save("C:\\Users\\GuohaoZhang\\Dropbox\\data\\normal_s4_tensorboy.trk"); return 1; tractData.Read("C:\\Users\\GuohaoZhang\\Dropbox\\data\\normal_s3_tensorboy_RevZ.trk"); //tractData.Read("data\\normal_s5.tensorinfo"); //tractData.Read("data\\normal_s5_2pt.tensorinfo"); //tractData.Read("data\\cFile.tensorinfo"); //tractData.Read("C:\\Users\\GuohaoZhang\\Desktop\\tmpdata\\dti.trk"); //tractData.Read("C:\\Users\\GuohaoZhang\\Desktop\\tmpdata\\ACR.trk"); //tractData.Read("dti_20_0995.data"); track.SetTracts(&tractData); track.SetTexture(gTex); //track.SetShape(MyTractVisBase::TRACK_SHAPE_LINE); track.SetShape(MyTractVisBase::TrackShape(trackShape + 1)); track.ComputeGeometry(); track.LoadShader(); track.LoadGeometry(); trackLine.SetTracts(&tractData); trackLine.SetShape(MyTractVisBase::TRACK_SHAPE_LINE); trackLine.ComputeGeometry(); trackLine.LoadShader(); trackLine.LoadGeometry(); track.SetToInfluence(tractEncoding); MyVec3f center = track.GetTracts()->GetBoundingBox().GetCenter(); cout << "Center: " << center[0] << ", " << center[1] << ", " << center[2] << endl; #endif #ifdef MESH gTex = MakeTexture("2dir_128.bmp"); meshPrecision = 0.01; //mesh.Read("data\\lh.trans.pial.obj"); mesh.Read("data\\lh.pial.DK.fusiform_trans.obj"); //mesh.Read("lh.pial.obj"); //mesh.Read("data\\lh.trans.pial.obj"); //MyMesh mesh2; //mesh2.Read("data\\rh.trans.pial.obj"); //mesh.Merge(mesh2); mesh.MergeVertices(meshPrecision); mesh.GenPerVertexNormal(); //mesh.Write("data\\rh.trans_wnormal.pial.obj"); mesh.CompileShader(); mesh.mTexture = gTex; mesh.Build(); //glEnable(GL_BLEND); //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); #endif /****************************************/ /* Here's the GLUI code */ /****************************************/ printf("GLUI version: %3.2f\n", GLUI_Master.get_version()); GLUI_Master.set_glutDisplayFunc(myGlutDisplay); GLUI_Master.set_glutReshapeFunc(myGlutReshape); GLUI_Master.set_glutKeyboardFunc(myGlutKeyboard); GLUI_Master.set_glutSpecialFunc(NULL); GLUI_Master.set_glutMouseFunc(myGlutMouse); glui = GLUI_Master.create_glui_subwindow(main_window, GLUI_SUBWINDOW_RIGHT); glui->set_main_gfx_window(main_window); // add panels for parameter tunning panel[0] = new GLUI_Panel(glui, "Rendering Mode"); GLUI_Spinner* dsrSpinner = new GLUI_Spinner( panel[0], "DSR Index", GLUI_SPINNER_INT, &dsrIndex, -1, changeDsr); dsrSpinner->set_int_limits(1, 4); GLUI_RadioGroup* radioGroup = new GLUI_RadioGroup(panel[0], &renderIdx, 0, switchRenderMode); new GLUI_RadioButton(radioGroup, "Geometry Pass"); new GLUI_RadioButton(radioGroup, "SSAO Pass"); new GLUI_RadioButton(radioGroup, "Blur Pass"); new GLUI_RadioButton(radioGroup, "Lighting Pass"); new GLUI_Button(panel[0], "Reset All", -1, resetRenderingParameters); new GLUI_Button(panel[0], "Reset Shaders", -1, resetShaders); // geometry pass panel[1] = new GLUI_Panel(glui, "Geometry Pass"); new GLUI_Button(panel[1], "Reset", 0, resetRenderingParameters); new GLUI_Checkbox(panel[1], "Cull Backface", &cullface, -1, changeCullface); new GLUI_Checkbox(panel[1], "Draw Tracts", &bdrawTracks, -1, reRender); new GLUI_Checkbox(panel[1], "Draw Axes", &bdrawAxes, -1, reRender); #ifdef MESH GLUI_Spinner* meshPrecisionSpinner = new GLUI_Spinner (panel[1], "Mesh Detail", GLUI_SPINNER_FLOAT, &meshPrecision, -1, changeMeshPrecision); meshPrecisionSpinner->set_float_limits(0.01, 10); #endif #ifdef TRACK GLUI_RadioGroup* shapeRadioGroup = new GLUI_RadioGroup(panel[1], &trackShape, 0, changeTrackShape); new GLUI_RadioButton(shapeRadioGroup, "Line"); new GLUI_RadioButton(shapeRadioGroup, "Tube"); new GLUI_RadioButton(shapeRadioGroup, "Superquadric"); GLUI_RadioGroup* encodingRadioGroup = new GLUI_RadioGroup(panel[1], &tractEncoding, 0, changeTractEncoding); new GLUI_RadioButton(encodingRadioGroup, "Boy's"); new GLUI_RadioButton(encodingRadioGroup, "Color"); new GLUI_RadioButton(encodingRadioGroup, "Size"); new GLUI_RadioButton(encodingRadioGroup, "Texture"); tubeParameterPanel = new GLUI_Panel(panel[1], "Tube Parameters"); new GLUI_StaticText(tubeParameterPanel, "Tube Radius"); GLUI_Scrollbar* tubeRadiusSlider = new GLUI_Scrollbar (tubeParameterPanel, "Tube Radius", GLUI_SCROLL_HORIZONTAL, &(track.mTrackRadius), -1, reRender); tubeRadiusSlider->set_float_limits(0, 1); GLUI_Spinner* boxOpacitySpinner = new GLUI_Spinner( tubeParameterPanel, "Opacity Index", GLUI_SPINNER_INT, &boxOpacityIndex, -1, reRender); boxOpacitySpinner->set_int_limits(0, 2); GLUI_Spinner* trackFaceSpinner = new GLUI_Spinner( tubeParameterPanel, "Number Faces", GLUI_SPINNER_INT, &trackFaces, -1, changeTrackShape); trackFaceSpinner->set_int_limits(2, 20); trackFaceSpinner->set_int_val(track.GetNumberFaces()); #endif // ssao pass panel[2] = new GLUI_Panel(glui, "SSAO Pass"); new GLUI_Button(panel[2], "Reset", 1, resetRenderingParameters); new GLUI_StaticText(panel[2], "Sample Radius"); GLUI_Scrollbar* sampleRadiusSlider = new GLUI_Scrollbar (panel[2], "Sample Radius", GLUI_SCROLL_HORIZONTAL, &(ssaoPass.mSampleRadius), -1, reRender); sampleRadiusSlider->set_float_limits(0, 100); new GLUI_StaticText(panel[2], "Occlusion Power"); GLUI_Scrollbar* occulusioPowerSlider = new GLUI_Scrollbar (panel[2], "Occlusion Power", GLUI_SCROLL_HORIZONTAL, &(ssaoPass.mOcclusionPower), -1, reRender); occulusioPowerSlider->set_float_limits(0, 4); // blur pass panel[3] = new GLUI_Panel(glui, "Blur Pass"); new GLUI_Button(panel[3], "Reset", 2, resetRenderingParameters); GLUI_Spinner* blurRadiusSpinner = new GLUI_Spinner (panel[3], "Blur Radius (Pixel)", GLUI_SPINNER_INT, &(blurPass.mBlurRadius), -1, reRender); blurRadiusSpinner->set_int_limits(0, 20); // lighting pass lightingPass.mAmbient = 0.4; lightingPass.mDiffuse = 0.6; lightingPass.mSpecular = 0; lightingPass.mUseSsao = 1; panel[4] = new GLUI_Panel(glui, "Lighting Pass"); new GLUI_Button(panel[4], "Reset", 3, resetRenderingParameters); new GLUI_Checkbox(panel[4], "Normalize Intensity", &lightComponentRatioControl, -1, changeLightComponent); new GLUI_Checkbox(panel[4], "Use SSAO", &lightingPass.mUseSsao, -1, changeLightComponent); new GLUI_StaticText(panel[4], "Light Intensity"); GLUI_Scrollbar* lightIntensitySlider = new GLUI_Scrollbar (panel[4], "Light Intensity", GLUI_SCROLL_HORIZONTAL, &(lightingPass.mLightItensity), -1, reRender); lightIntensitySlider->set_float_limits(0, 10); new GLUI_StaticText(panel[4], "Ambient"); lightComponentSlider[0] = new GLUI_Scrollbar (panel[4], "Ambient", GLUI_SCROLL_HORIZONTAL, &(lightingPass.mAmbient), 0, changeLightComponent); lightComponentSlider[0]->set_float_limits(0, 1); new GLUI_StaticText(panel[4], "Diffuse"); lightComponentSlider[1] = new GLUI_Scrollbar (panel[4], "Diffuse", GLUI_SCROLL_HORIZONTAL, &(lightingPass.mDiffuse), 1, changeLightComponent); lightComponentSlider[1]->set_float_limits(0, 1); new GLUI_StaticText(panel[4], "Specular"); lightComponentSlider[2] = new GLUI_Scrollbar (panel[4], "Specular", GLUI_SCROLL_HORIZONTAL, &(lightingPass.mSpecular), 2, changeLightComponent); lightComponentSlider[2]->set_float_limits(0, 1); new GLUI_StaticText(panel[4], "Shininess"); GLUI_Scrollbar* shininessSlider = new GLUI_Scrollbar (panel[4], "Shininess", GLUI_SCROLL_HORIZONTAL, &(lightingPass.mShininess), -1, changeLightComponent); shininessSlider->set_float_limits(0, 128); // set init state right switchRenderMode(renderIdx); glutMainLoop(); return EXIT_SUCCESS; }
void changeMeshPrecision(int mode){ mesh.Read("data\\lh.pial.obj"); mesh.MergeVertices(meshPrecision); mesh.GenPerVertexNormal(); mesh.Build(); }
// Begin main function int main (int argc, char** argv){ //PerfLog P("Example 2 Program"); //P.push("init","Program Initilization"); // Gather command-line options UserOptions user = gather_command_line(argc, argv); // Initialize libraries LibMeshInit init (argc, argv); // Initilize the mesh and order variables MyMesh mesh; Order order; // Patch test (Bhatti Example 8-1) if(user.get_flag("patch")){ GMVIO(mesh).read("../data/fem/examples/input/example2.gmv"); mesh.all_first_order(); order = FIRST; // 2-D box } else if (user.get_flag("2D")){ MeshTools::Generation::build_square(mesh, 10, 10, 0., 0.04, 0., 0.04, TRI6); mesh.all_second_order(); order = SECOND; // 3-D box } else if (user.get_flag("3D")){ MeshTools::Generation::build_cube(mesh, 10, 10, 10, 0., 0.04, 0., 0.04, 0., 0.04, TET10); mesh.all_second_order(); order = SECOND; // Multi-element implementation of Bhatti Exmample 8-1 } else { mesh.set_mesh_dimension(2); mesh.add_point(Point(0,0)); mesh.add_point(Point(0.02,0)); mesh.add_point(Point(0.02,0.04)); mesh.add_point(Point(0,0.02)); TriangleInterface t(mesh); t.desired_area() = 1e-4; t.triangulation_type() = TriangleInterface::PSLG; t.smooth_after_generating() = true; t.triangulate(); mesh.all_second_order(); order = SECOND; } // Create an equation system EquationSystems eq_sys(mesh); // Create a HeatEq class boost::shared_ptr<HeatEq> heateq(new HeatEq(eq_sys, order)); // Define the material constants heateq->system().set_constant<Real>("k", user.get<Real>("conductivity")); heateq->system().set_constant<Real>("rho", user.get<Real>("density")); heateq->system().set_constant<Real>("cp", user.get<Real>("specific-heat")); // Link to the initialization function heateq->system().add_initial_function(initial_function); // Add boundary IDs (this is some custom functionality that I added) mesh.find_neighbors(); mesh.boundary_info->clear(); mesh.add_boundary_id(0, "y", 0.0); // bottom mesh.add_boundary_id(1, "x", 0.02); // right mesh.add_boundary_id(2, "x", 0.0); // left mesh.add_boundary_id(3); // top // Convection boundary at bottom (user-specified) pConvection pC = heateq->system().add_boundary<HeatEqBoundaryConvection>(0); pC->h_constant = user.get<Real>("h-coefficient"); pC->Tinf_constant = user.get<Real>("Tinf"); // Flux boundary at right-side (user-specified) pNeumann pN = heateq->system().add_boundary<HeatEqBoundaryNeumann>(1); pN->q_constant = user.get<Real>("flux"); // Flux boundary at left-side (symetry; defaults to q = 0) heateq->system().add_boundary<HeatEqBoundaryNeumann>(2); // Top constant temperature boundary pDirichlet pD = heateq->system().add_boundary<HeatEqBoundaryDirichlet>(3); pD->fptr = dirichlet_function; // links the boundary function // Initialize system heateq->system().init(0.0); // Define a general filename FileParts outfile("../data/fem/examples/output/example2.ex2"); // Export the initial mesh //ExodusII_IO(mesh).write_equation_systems(outfile.add_tstep(0,3,"_"), eq_sys); MyVTKIO vtk("../data/fem/examples/output/example2.vtu", eq_sys); vtk.write(0.0); // Define time stepping variables Real time = 0.; Real dt = user.get<Real>("dt"); //P.pop("init"); //P.push("soln", "Transient Solution"); // Begin the time loop int N = user.get<int>("num-steps"); int d = user.get<int>("output-div"); for (int t_step = 0; t_step < N; t_step++){ // Incremenet the time counter, set the time and the // time step size as parameters in the EquationSystem. time += dt; // Display a progress message printf("time = %f; step %d of %d\n", time, t_step, N); // Update the old solution vector heateq->system().update_solution(time, dt); //! \todo This needs to be incoporated into the HeatEqSystem heateq->system().reinit(); heateq->system().rhs->zero(); // Solve the system heateq->system().solve(); // Output evey 10 timesteps to file. if ( (t_step+1)%d == 0){ std::string out = outfile.add_tstep(t_step+1,3,"_"); //ExodusII_IO(mesh).write_equation_systems(out, eq_sys); vtk.write(time); } } //P.pop("soln"); // All done. return 0; }
static int LoadMesh ( const char * filename, std::vector<Surfel<Real> >& pSurfel,vcg::CallBackPos *cb = 0) { MyMesh mesh; int mask = 0; mesh.Clear(); if (cb != NULL) (*cb)(0, "Loading Model..."); vcg::tri::io::PlyInfo info; info.cb = cb; vcg::tri::io::ImporterPLY<MyMesh>::LoadMask(filename, mask,info); vcg::tri::io::ImporterPLY<MyMesh>::Open(mesh,filename,info); bool normal_per_vertex = false; if (mask & vcg::tri::io::Mask::IOM_VERTNORMAL) normal_per_vertex = true; bool color_per_vertex = false; if (mask & vcg::tri::io::Mask::IOM_VERTCOLOR) color_per_vertex = true; bool quality_per_vertex = false; if (mask & vcg::tri::io::Mask::IOM_VERTQUALITY) quality_per_vertex = true; bool radius_per_vertex = false; if (mask & vcg::tri::io::Mask::IOM_VERTRADIUS) radius_per_vertex = true; unsigned int pos = 0; Surfel<Real> s; for (MyMesh::VertexIterator vit = mesh.vert.begin(); vit != mesh.vert.end(); ++vit) { Point3f v = (*vit).P(); Point3f n = (*vit).N(); Color4b c (0.2, 0.2, 0.2, 1.0); if (color_per_vertex) { c = Color4b ((GLubyte)(*vit).C()[0], (GLubyte)(*vit).C()[1], (GLubyte)(*vit).C()[2], 1.0); } Real radius = 0.25; if (radius_per_vertex) { radius = static_cast<Real> (((*vit).R())); } Real quality = 1.0; if (quality_per_vertex) quality = static_cast<Real> ((*vit).Q()); s = Surfel<Real> (v, n, c, radius, pos); s.SetRadius(radius); pSurfel.push_back (s); ++pos; } std::cout << "Surfel " << pSurfel.size() << std::endl; if (cb != NULL) (*cb)(99, "Done"); mesh.Clear(); return 0; }