voxel material::intersect_ray(kdtree* tree, glm::vec3& pos, glm::vec3& dir, glm::vec3& inv_dir) { if (!tree) return voxel(); if (tree->box_.intersect(pos, inv_dir)) { if (tree->right_ == tree->left_) { // TODO at the moment we only have bounding boxes kdtree_leaf* leaf = static_cast<kdtree_leaf*>(tree); return ::intersect_ray(*this, pos, dir, leaf->indices_); } else { voxel v0 = intersect_ray(tree->left_, pos, dir, inv_dir); voxel v1 = intersect_ray(tree->right_, pos, dir, inv_dir); return v0.dist < v1.dist ? v0 : v1; } } else return voxel(); }
double Transform:: CheckVoxel(int x, int y, int z) { double thisvalue=(*dataCube)(x,y,z); if (thisvalue<absolutelowthreshold) return 0; if (thisvalue>absolutehighthreshold) return 1; Vector<int> voxel(3), meansize(3); voxel[1]=x; voxel[2]=y; voxel[3]=z; meansize[1]=2; meansize[2]=2; meansize[3]=0;//2 test!!! double mean=stat.meanValue(voxel,meansize); int structcounter=0; for (Neigbour n=TopFront;n<END;n=(Neigbour)(n+1) ) if (n!=THIS) { double nvalue=GetNeigbourOfVoxelNr(n,voxel); if (nvalue>(mean+epsilon)) { structcounter++; } } if (thisvalue>(mean+epsilon) && structcounter>1) return 0.65; return 0; }
std::vector<Voxel> soustractionVoxelCylindre(Point origineAxe, Vector axeVecteur, double rayon, Point centreVoxel, double rayonVoxel, double resolution){ std::vector<Voxel> listeVoxel; Voxel v(centreVoxel, rayonVoxel); if(voxelHorsCylindre(origineAxe,axeVecteur, rayon,v)){ listeVoxel.push_back(v); }else if( rayonVoxel > resolution && !voxelAppartientCylindre(origineAxe, axeVecteur,rayon,v)){ for(int i=0; i<8; i++){ Point centreSubVoxel( (v.getSommet(i).getX()+centreVoxel.getX())/2, (v.getSommet(i).getY()+centreVoxel.getY())/2, (v.getSommet(i).getZ()+centreVoxel.getZ())/2 ); Voxel voxel(centreSubVoxel, rayonVoxel/2); if(voxelHorsCylindre(origineAxe,axeVecteur, rayon,voxel)){ listeVoxel.push_back(voxel); }else if (!voxelAppartientCylindre(origineAxe, axeVecteur,rayon,voxel)){ std::vector<Voxel> listeTmp; listeTmp = soustractionVoxelCylindre(origineAxe, axeVecteur, rayon, centreSubVoxel, rayonVoxel/2, resolution); for(Voxel vox : listeTmp){ listeVoxel.push_back(vox); } } } } return listeVoxel; }
std::vector<Voxel> sphereVolumique(Point centre, double rayon, double resolution){ DrawCircle(0,0,rayon,100); std::vector<Voxel> listeVoxel; Voxel v(centre, rayon); if( voxelAppartientSphere(v, centre, rayon)){ listeVoxel.push_back(v); }else if ( v.getRayon() > resolution){ for(int i=0; i<8; i++){ Point centreSubVoxel( (v.getSommet(i).getX()+centre.getX())/2, (v.getSommet(i).getY()+centre.getY())/2, (v.getSommet(i).getZ()+centre.getZ())/2 ); Voxel voxel(centreSubVoxel, rayon/2); if(voxelAppartientSphere(voxel, centre, rayon)){ listeVoxel.push_back(v); }else if (!voxelHorsSphere(voxel,centre, rayon)){ std::vector<Voxel> listeTmp = voxelSphere(centre, rayon, centreSubVoxel, rayon/2, resolution); for(Voxel vox : listeTmp){ listeVoxel.push_back(vox); } } } } return listeVoxel; }
std::vector<Voxel> voxelSphere(Point centreSphere,double rayonSphere, Point centreVoxel, double rayonVoxel, double resolution){ std::vector<Voxel> listeVoxel; Voxel v(centreVoxel, rayonVoxel); if(voxelAppartientSphere(v, centreSphere, rayonSphere)){ listeVoxel.push_back(v); }else if( rayonVoxel > resolution && !voxelHorsSphere(v,centreSphere,rayonSphere)){ for(int i=0; i<8; i++){ Point centreSubVoxel( (v.getSommet(i).getX()+centreVoxel.getX())/2, (v.getSommet(i).getY()+centreVoxel.getY())/2, (v.getSommet(i).getZ()+centreVoxel.getZ())/2 ); Voxel voxel(centreSubVoxel, rayonVoxel/2); if(voxelAppartientSphere(voxel, centreSphere, rayonSphere)){ listeVoxel.push_back(voxel); }else if (!voxelHorsSphere(voxel,centreSphere, rayonSphere)){ std::vector<Voxel> listeTmp = voxelSphere(centreSphere, rayonSphere, centreSubVoxel, rayonVoxel/2, resolution); for(Voxel vox : listeTmp){ listeVoxel.push_back(vox); } } } } return listeVoxel; }
void effect1(){ int i; int x,y,z; int v[3]; for(i=0; i<180*3; i+=3) { b[i+0]+=sin(i/3); b[i+1]=0; b[i+2]+=cos(i/3); voxel( b[i+0], b[i+1], b[i+2]); } }
void Sculpture::addTrianglesToZbuffer(vector<Triangle>& triangles, Zbuffer& zBuff, ImageData& imgData) { for(int i = 0; i < triangles.size(); ++i) { for (int j = 0 ; j < 3 ; ++j) { double x = (triangles[i].p)[j][0], y = (triangles[i].p)[j][1], z = (triangles[i].p)[j][2]; getProjection(x, y, z, imgData.P); if (x >= imgData.image.cols || x < 0 || y >= imgData.image.rows || y < 0 || pointOffSilhouette(imgData.silhouette, x, y)) { continue; } Vec3f voxel((triangles[i].p)[j][0],(triangles[i].p)[j][1],(triangles[i].p)[j][2]); zBuff.addVertex(x, y, voxel, imgData.rt); } } }
void Map::voxelizeMap(void) { point pt; for (int y = 0; y < CUBE_SIZE; y++) { for (int x = 0; x < CUBE_SIZE; x++) { pt = interPoint(x, y); for (int l = 0; l < pt.z; l++) { this->_vox[l][y][x] = voxel(voxel::SOIL, l); this->_hMap[x + y * CUBE_SIZE] = pt.z; } } } }
std::vector<Voxel> cylindreVolumique(Point origineAxe, Vector axeVecteur, double rayon,double resolution){ afficheCylindre(10); Point limite(origineAxe.getX()+axeVecteur.getX(), origineAxe.getY()+axeVecteur.getY(),origineAxe.getZ()+axeVecteur.getZ()); int distanceLimite = sqrt( pow(limite.getX()-origineAxe.getX(),2) + pow(limite.getY()-origineAxe.getY(),2) + pow(limite.getZ()-origineAxe.getZ(),2) ); Voxel v(origineAxe, distanceLimite); std::vector<Voxel> listeVoxel; if( voxelAppartientCylindre(origineAxe,axeVecteur, rayon,v)){ listeVoxel.push_back(v); }else if ( v.getRayon() > resolution){ for(int i=0; i<8; i++){ Point centreSubVoxel( (v.getSommet(i).getX()+origineAxe.getX())/2, (v.getSommet(i).getY()+origineAxe.getY())/2, (v.getSommet(i).getZ()+origineAxe.getZ())/2 ); Voxel voxel(centreSubVoxel, distanceLimite/2); if(voxelAppartientCylindre(origineAxe,axeVecteur, rayon,voxel)){ listeVoxel.push_back(voxel); }else if (!voxelHorsCylindre(origineAxe,axeVecteur, rayon,voxel)){ std::vector<Voxel> listeTmp; listeTmp = voxelCylindre(origineAxe, axeVecteur, rayon, centreSubVoxel, distanceLimite/2, resolution); for(Voxel vox : listeTmp){ listeVoxel.push_back(vox); } } } } return listeVoxel; }
void PhysiK::TriangleHashTable::addObject(Body *body){ for(unsigned int triangleOffset = 0 ; triangleOffset<body->nbTriangles ; triangleOffset++){ Particle * particules[3]; for(int j = 0 ; j < 3 ; j++) particules[j] = body->getPositions()+body->getTriangles()[triangleOffset][j]; vec3 min; vec3 max; //on cherche le minimum et le maximum for(int j = 0 ; j < 3 ; j++){ min[j] = std::min(std::min(particules[0]->pos[j],particules[1]->pos[j]),particules[2]->pos[j]); max[j] = std::max(std::max(particules[0]->pos[j],particules[1]->pos[j]),particules[2]->pos[j]); } vec3 min_voxel = min.toVoxel()-1.f; vec3 max_voxel = max.toVoxel()+1.f; for(float x = min_voxel.x ; x < max_voxel.x ; x++){ for(float y = min_voxel.y ; y < max_voxel.y ; y++){ for(float z = min_voxel.z ; z < max_voxel.z ; z++){ vec3 voxel(x,y,z); Particle par(voxel.center().toWorld()); //aproximate the cube with a particule CollisionParticuleTriangleConstraint to_test( &par, particules[0], particules[1], particules[2], vec3::voxelSize*sqrt(2.f)*0.5); if(to_test.eval()!=0){ voxelGrid[voxel].push_back(std::make_pair(body,triangleOffset)); } } } } } }
voxel operator+(const voxel& v) const { return voxel(v.x + x, v.y + y, v.z + z); };
void ModelMesher::generateOffsetSurface(double offset) { if(m->activeNode == nullptr) return; auto n = m->activeNode; n->vis_property["isSmoothShading"].setValue(true); switch(m->QObject::property("meshingIsThick").toInt()){ case 0: break; case 1: offset *= 1.5; break; case 2: offset *= 2; break; } double dx = 0.015; std::vector<SDFGen::Vec3f> vertList; std::vector<SDFGen::Vec3ui> faceList; //start with a massive inside out bound box. SDFGen::Vec3f min_box(std::numeric_limits<float>::max(),std::numeric_limits<float>::max(),std::numeric_limits<float>::max()), max_box(-std::numeric_limits<float>::max(),-std::numeric_limits<float>::max(),-std::numeric_limits<float>::max()); Structure::Curve* curve = dynamic_cast<Structure::Curve*>(n); Structure::Sheet* sheet = dynamic_cast<Structure::Sheet*>(n); //generate "tri-mesh" from skeleton geometry if(curve) { QVector<QVector3D> cpts; for(auto p : curve->controlPoints()) cpts << QVector3D(p[0],p[1],p[2]); cpts = GeometryHelper::uniformResampleCount(cpts, cpts.size() * 5); int vi = 0; for(size_t i = 1; i < cpts.size(); i++){ SDFGen::Vec3f p0 (cpts[i-1][0],cpts[i-1][1],cpts[i-1][2]); SDFGen::Vec3f p1 (cpts[i][0],cpts[i][1],cpts[i][2]); SDFGen::Vec3f p2 = (p0 + p1) * 0.5; vertList.push_back(p0); vertList.push_back(p1); vertList.push_back(p2); faceList.push_back(SDFGen::Vec3ui(vi+0,vi+1,vi+2)); vi += 3; update_minmax(p0, min_box, max_box); update_minmax(p1, min_box, max_box); update_minmax(p2, min_box, max_box); } } if(sheet) { // Build surface geometry if needed auto & surface = sheet->surface; if(surface.quads.empty()){ double resolution = (surface.mCtrlPoint.front().front() - surface.mCtrlPoint.back().back()).norm() * 0.1; surface.generateSurfaceQuads( resolution ); } int vi = 0; for(auto quad : surface.quads) { QVector<SDFGen::Vec3f> p; for(int i = 0; i < 4; i++){ SDFGen::Vec3f point(quad.p[i][0],quad.p[i][1],quad.p[i][2]); p << point; update_minmax(point, min_box, max_box); } vertList.push_back(p[0]); vertList.push_back(p[1]); vertList.push_back(p[2]); faceList.push_back(SDFGen::Vec3ui(vi+0,vi+1,vi+2)); vi += 3; vertList.push_back(p[0]); vertList.push_back(p[2]); vertList.push_back(p[3]); faceList.push_back(SDFGen::Vec3ui(vi+0,vi+1,vi+2)); vi += 3; } } int padding = 10; SDFGen::Vec3f unit(1,1,1); min_box -= unit*padding*dx; max_box += unit*padding*dx; SDFGen::Vec3ui sizes = SDFGen::Vec3ui((max_box - min_box)/dx); if (faceList.empty() || vertList.empty()) return; Array3f phi_grid; SDFGen::make_level_set3(faceList, vertList, min_box, dx, sizes[0], sizes[1], sizes[2], phi_grid, false, offset * 2.0); ScalarVolume volume = initScalarVolume(sizes[0], sizes[1], sizes[2], (sizes[0] + sizes[1] + sizes[2])*dx); for(int i = 0; i < sizes[0]; i++){ for(int j = 0; j < sizes[1]; j++){ for(int k = 0; k < sizes[2]; k++){ volume[k][j][i] = phi_grid(i,j,k); } } } // Mesh surface from volume using marching cubes auto mesh = march(volume, offset); QSharedPointer<SurfaceMeshModel> newMesh = QSharedPointer<SurfaceMeshModel>(new SurfaceMeshModel()); int vi = 0; for(auto tri : mesh){ std::vector<SurfaceMeshModel::Vertex> verts; for(auto p : tri){ Vector3 voxel(p.x, p.y, p.z); Vector3 pos = (voxel * dx) + Vector3(min_box[0],min_box[1],min_box[2]); newMesh->add_vertex(pos); verts.push_back(SurfaceMeshModel::Vertex(vi++)); } newMesh->add_face(verts); } GeometryHelper::meregeVertices<Vector3>(newMesh.data()); newMesh->updateBoundingBox(); newMesh->update_face_normals(); newMesh->update_vertex_normals(); n->property["mesh"].setValue(newMesh); n->property["mesh_filename"].setValue(QString("meshes/%1.obj").arg(n->id)); }