Scene_interface::Bbox Scene_polylines_item::bbox() const { if(isEmpty()) return Bbox(); std::list<Point_3> boxes; for(std::list<std::vector<Point_3> >::const_iterator it = polylines.begin(); it != polylines.end(); ++it){ if(it->begin() != it->end()) { Iso_cuboid_3 cub = CGAL::bounding_box(it->begin(), it->end()); boxes.push_back((cub.min)()); boxes.push_back((cub.max)()); } } Iso_cuboid_3 bbox = boxes.begin() != boxes.end() ? CGAL::bounding_box(boxes.begin(), boxes.end()) : Iso_cuboid_3(); return Bbox(bbox.xmin(), bbox.ymin(), bbox.zmin(), bbox.xmax(), bbox.ymax(), bbox.zmax()); }
Bbox bbox() const { if(isEmpty()) return Bbox(); else { CGAL::Bbox_3 result = c3t3().triangulation().finite_vertices_begin()->point().bbox(); for(Tr::Finite_vertices_iterator vit = ++c3t3().triangulation().finite_vertices_begin(), end = c3t3().triangulation().finite_vertices_end(); vit != end; ++vit) { result = result + vit->point().bbox(); } return Bbox(result.xmin(), result.ymin(), result.zmin(), result.xmax(), result.ymax(), result.zmax()); } }
void Scene_c3t3_item::compute_bbox() const { if (isEmpty()) _bbox = Bbox(); else { CGAL::Bbox_3 result; for (Tr::Finite_vertices_iterator vit = ++c3t3().triangulation().finite_vertices_begin(), end = c3t3().triangulation().finite_vertices_end(); vit != end; ++vit) { if(vit->in_dimension() == -1) continue; result = result + vit->point().bbox(); } _bbox = Bbox(result.xmin(), result.ymin(), result.zmin(), result.xmax(), result.ymax(), result.zmax()); } }
void Scene_c3t3_item::compute_bbox() const { if (isEmpty()) _bbox = Bbox(); else { CGAL::Bbox_3 result = c3t3().cells_in_complex_begin()->vertex(0)->point().bbox(); for (C3t3::Cells_in_complex_iterator cit = ++c3t3().cells_in_complex_begin(), cend = c3t3().cells_in_complex_end(); cit != cend; ++cit) { result = result + cit->vertex(0)->point().bbox(); //only one vertex should be a satisfactory approximation } _bbox = Bbox(result.xmin(), result.ymin(), result.zmin(), result.xmax(), result.ymax(), result.zmax()); } }
Scene_combinatorial_map_item::Bbox Scene_combinatorial_map_item::bbox() const { typedef Combinatorial_map_3::Attribute_const_range<0>::type Point_range; const Point_range& points=combinatorial_map().attributes<0>(); CGAL::Bbox_3 bbox=points.begin()->point().bbox(); for(Point_range::const_iterator pit=boost::next(points.begin());pit!=points.end();++pit) bbox=bbox+pit->point().bbox(); return Bbox(bbox.xmin(),bbox.ymin(),bbox.zmin(), bbox.xmax(),bbox.ymax(),bbox.zmax()); }
void Scene_polyhedron_transform_item::compute_bbox() const { const Kernel::Point_3& p = *(poly->points_begin()); CGAL::Bbox_3 bbox(p.x(), p.y(), p.z(), p.x(), p.y(), p.z()); for(Polyhedron::Point_const_iterator it = poly->points_begin(); it != poly->points_end(); ++it) { bbox = bbox + it->bbox(); } _bbox = Bbox(bbox.xmin(),bbox.ymin(),bbox.zmin(), bbox.xmax(),bbox.ymax(),bbox.zmax()); }
Scene_textured_polyhedron_item::Bbox Scene_textured_polyhedron_item::bbox() const { const Point& p = *(poly->points_begin()); CGAL::Bbox_3 bbox(p.x(), p.y(), p.z(), p.x(), p.y(), p.z()); for(Textured_polyhedron::Point_iterator it = poly->points_begin(); it != poly->points_end(); ++it) { bbox = bbox + it->bbox(); } return Bbox(bbox.xmin(),bbox.ymin(),bbox.zmin(), bbox.xmax(),bbox.ymax(),bbox.zmax()); }
//----------------------------------------------------------------------------- ImplicitMesh::ImplicitMesh(SimpleMesh * mesh) : mSourceMesh(mesh), mData(NULL) { // Loop through all vertices in the mesh to determine the smallest // bounding box needed Vector3<float> pMin((std::numeric_limits<float>::max)(), (std::numeric_limits<float>::max)(), (std::numeric_limits<float>::max)()); Vector3<float> pMax(-(std::numeric_limits<float>::max)(), -(std::numeric_limits<float>::max)(), -(std::numeric_limits<float>::max)()); const std::vector<SimpleMesh::Vertex>& verts = mSourceMesh->GetVerts(); for(unsigned int i=0; i < verts.size(); i++){ const SimpleMesh::Vertex &v = verts.at(i); for (int j = 0; j < 3; j++) { if (pMin[j] > v.pos[j]) pMin[j] = v.pos[j]; if (pMax[j] < v.pos[j]) pMax[j] = v.pos[j]; } } // Pad with 0.1 to get around border issues Vector3<float> pad(0.1, 0.1, 0.1); pMin -= pad; pMax += pad; mBox = Bbox(pMin, pMax); std::cout << "Bounding box of implicit mesh: " << mBox << std::endl; }
void Scene::update_bbox() { std::cout << "Compute bbox..."; m_bbox = Bbox(); if(m_pPolyhedron == NULL) { std::cout << "failed (no polyhedron)." << std::endl; return; } if(m_pPolyhedron->empty()) { std::cout << "failed (empty polyhedron)." << std::endl; return; } Polyhedron::Point_iterator it = m_pPolyhedron->points_begin(); m_bbox = (*it).bbox(); for(; it != m_pPolyhedron->points_end(); it++) m_bbox = m_bbox + (*it).bbox(); std::cout << "done (" << m_pPolyhedron->size_of_facets() << " facets)" << std::endl; }
Cube::Cube() { Vector3<float> lowP(-1.1, -1.1, -1.1); Vector3<float> highP(1.1, 1.1, 1.1); SetBoundingBox(Bbox(lowP, highP)); Matrix4x4<float> matrix; matrix(0,0) = 0.0; matrix(1,1) = 0.0; matrix(2,2) = 0.0; matrix(3,3) = 0.0; matrix(0,3) = 0.0; matrix(1,3) = 0.5; matrix(2,3) = 0.0; // Plane 1 Quadric* q = new Quadric(matrix); q->Translate(0.0, 0.5, 0); q->SetBoundingBox(Bbox(lowP, highP)); mPlanes.push_back(q); // Plane 2 matrix(0,3) = 0.0; matrix(1,3) = -0.5; matrix(2,3) = 0.0; q = new Quadric(matrix); q->Translate(0.0, -0.5, 0); q->SetBoundingBox(Bbox(lowP, highP)); mPlanes.push_back(q); // Plane 3 matrix(0,3) = 0.5; matrix(1,3) = 0.0; matrix(2,3) = 0.0; q = new Quadric(matrix); q->Translate(0.5, 0.0, 0); q->SetBoundingBox(Bbox(lowP, highP)); mPlanes.push_back(q); // Plane 4 matrix(0,3) = -0.5; matrix(1,3) = 0.0; matrix(2,3) = 0.0; q = new Quadric(matrix); q->Translate(-0.5, 0, 0); q->SetBoundingBox(Bbox(lowP, highP)); mPlanes.push_back(q); // Plane 5 matrix(0,3) = 0.0; matrix(1,3) = 0.0; matrix(2,3) = 0.5; q = new Quadric(matrix); q->Translate(0.0, 0.0, 0.5); q->SetBoundingBox(Bbox(lowP, highP)); mPlanes.push_back(q); // Plane 6 matrix(0,3) = 0.0; matrix(1,3) = 0.0; matrix(2,3) = -0.5; q = new Quadric(matrix); q->Translate(0.0, 0, -0.5); q->SetBoundingBox(Bbox(lowP, highP)); mPlanes.push_back(q); }
//----------------------------------------------------------------------------- //! @brief Creates a square model //! @remark //----------------------------------------------------------------------------- CreatedModel CreateSquare(const SquareCreationParams& params) { CreatedModel square; GameResource& gameResource = *(GameResource*)params.m_resource; square.boundingBox = Bbox(Vector3(params.m_lowerleft.x(), params.m_lowerleft.y(), 0.0f), Vector3(params.m_upperright.x(), params.m_upperright.y(), 0.0f)); square.model = new Model(); if (square.model->getMeshData().empty()) { unsigned int bufferSize = 4 * (3 + 2) * sizeof(float); byte vertexData[4 * (3 + 2) * sizeof(float)]; //4 points with position and 1 2D textureCoordinates byte* data = vertexData; *(float*)data = params.m_lowerleft.x(); data += sizeof(float); *(float*)data = params.m_lowerleft.y(); data += sizeof(float); *(float*)data = 0.0f; data += sizeof(float); *(float*)data = 0.0f; data += sizeof(float); *(float*)data = 0.0f; data += sizeof(float); *(float*)data = params.m_upperright.x(); data += sizeof(float); *(float*)data = params.m_lowerleft.y(); data += sizeof(float); *(float*)data = 0.0f; data += sizeof(float); *(float*)data = 1.0f; data += sizeof(float); *(float*)data = 0.0f; data += sizeof(float); *(float*)data = params.m_upperright.x(); data += sizeof(float); *(float*)data = params.m_upperright.y(); data += sizeof(float); *(float*)data = 0.0f; data += sizeof(float); *(float*)data = 1.0f; data += sizeof(float); *(float*)data = 1.0f; data += sizeof(float); *(float*)data = params.m_lowerleft.x(); data += sizeof(float); *(float*)data = params.m_upperright.y(); data += sizeof(float); *(float*)data = 0.0f; data += sizeof(float); *(float*)data = 0.0f; data += sizeof(float); *(float*)data = 1.0f; data += sizeof(float); std::vector<unsigned int> texCoordDim; texCoordDim.push_back(2); VertexBuffer* vb = new VertexBuffer(); const Technique* technique = square.model->getMeshData()[0]->getShaderInstance().getMaterial().getEffect()->getTechnique("default"); VertexDecalartionDesctriptor vertexDesc; vertexDesc.textureCoordinateDimensions = texCoordDim; const VertexShader* shader = gameResource.getShaderCache().getVertexShader(technique->getVertexShader()); assert(shader); vb->createBufferAndLayoutElements(gameResource.getDeviceManager(), bufferSize, (void*)vertexData, false, vertexDesc, shader->getShaderBlob()); square.model->getMeshData().push_back(new MeshGroup(vb, 0, *(params.m_shaderInstance))); if (square.model->getMeshData()[0]->getShaderInstance().getMaterial().getEffect() == nullptr) { square.model->getMeshData()[0]->getShaderInstance().getMaterial().setEffect(gameResource.getEffectCache().getEffect("simple_effect.fx")); } data = nullptr; } else { square.model->getMeshData()[0]->setShaderInstance(*(params.m_shaderInstance)); if (square.model->getMeshData()[0]->getShaderInstance().getMaterial().getEffect() == nullptr) { square.model->getMeshData()[0]->getShaderInstance().getMaterial().setEffect(gameResource.getEffectCache().getEffect("simple_effect.fx")); } } square.model->getMeshData()[0]->getGeometryInstance().setPrimitiveType((unsigned int)D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); return square; }