template <typename PointT> typename pcl::gpu::kinfuLS::StandaloneMarchingCubes<PointT>::MeshPtr pcl::gpu::kinfuLS::StandaloneMarchingCubes<PointT>::convertTrianglesToMesh (const pcl::gpu::DeviceArray<pcl::PointXYZ>& triangles) { if (triangles.empty () ) { return MeshPtr (); } pcl::PointCloud<pcl::PointXYZ> cloud; cloud.width = (int)triangles.size (); cloud.height = 1; triangles.download (cloud.points); boost::shared_ptr<pcl::PolygonMesh> mesh_ptr ( new pcl::PolygonMesh () ); pcl::toPCLPointCloud2 (cloud, mesh_ptr->cloud); mesh_ptr->polygons.resize (triangles.size () / 3); for (size_t i = 0; i < mesh_ptr->polygons.size (); ++i) { pcl::Vertices v; v.vertices.push_back (i*3+0); v.vertices.push_back (i*3+2); v.vertices.push_back (i*3+1); mesh_ptr->polygons[i] = v; } return (mesh_ptr); }
MeshPtr Mesh::sphere( float radius, int nSubdivsU, int nSubdivsV, vec3_t center, float uMin, float uMax, float vMin, float vMax ) { MeshPtr m = MeshPtr( new Mesh() ); float dPhi = MATH_2PIf/nSubdivsU; float dTheta = MATH_PIf/nSubdivsV; float theta, phi; std::vector<Mesh::PointHandle> points; // y for (theta=MATH_PIf/2.0f+dTheta;theta<=(3.0f*MATH_PIf)/2.0f-dTheta;theta+=dTheta) { vec3_t p; float y = sin(theta); // x-z phi = 0.0f; for( int j = 0; j<nSubdivsU; ++j ) { p.x = cos(theta) * cos(phi); p.y = y; p.z = cos(theta) * sin(phi); p = p*radius + center; points.push_back( m->addPoint(p) ); phi+=dPhi; } } Mesh::PointHandle pole1 = m->addPoint( math::Vec3f(0.0f, 1.0f, 0.0f)*radius + center ); Mesh::PointHandle pole2 = m->addPoint( math::Vec3f(0.0f, -1.0f, 0.0f)*radius + center ); points.push_back(pole1); points.push_back(pole2); // add faces for( int j=0; j<nSubdivsV-3;++j ) { int offset = j*(nSubdivsU); int i = 0; for( i=0; i<nSubdivsU-1; ++i ) { m->addTriangle(points[offset+i+1], points[offset+i + nSubdivsU], points[offset+i]); m->addTriangle(points[offset+i+1], points[offset+i+nSubdivsU+1], points[offset+i + nSubdivsU]); } m->addTriangle(points[offset+0],points[offset+i + nSubdivsU],points[offset+i]); m->addTriangle(points[offset],points[offset + nSubdivsU],points[offset+i + nSubdivsU]); } for( int i=0; i<nSubdivsU-1; ++i ) { m->addTriangle(points[i+1], points[i],pole1); m->addTriangle(points[nSubdivsU*(nSubdivsV-3)+i], points[nSubdivsU*(nSubdivsV-3)+i+1], pole2); } m->addTriangle(points[0], points[nSubdivsU-1], pole1); m->addTriangle(points[nSubdivsV*(nSubdivsV-2)-1], points[nSubdivsU*(nSubdivsV-3)], pole2); return m; }
MeshWrapper::MeshWrapper(LoaderPtr loader, const std::string &obj_file, const std::string &image_file, int count, glm::vec3 scale, float reflectivity, float shineDamper) { this->mesh = MeshPtr(new Mesh(loader, obj_file, image_file)); this->mesh->texturedModel->texture->reflectivity = reflectivity; this->mesh->texturedModel->texture->shineDamper = shineDamper; createMatrixes(count, scale); }
Space::Space() { offset = 0; // Z of 1 means back as there is no perspective projection applied during render position.z = 1; // Initialize static resources if needed if (!shader) shader = ShaderPtr(new Shader{space_vert, space_frag}); if (!texture) texture = TexturePtr(new Texture{"stars.rgb", 512, 512}); if (!mesh) mesh = MeshPtr(new Mesh{shader, "quad.obj"}); }
MeshPtr Rotate(MeshPtr mesh, Quaternion<float> rotate) { GeometrySetPtr newGeom = Rotate(mesh->GetGeometrySet(), rotate); return MeshPtr(new Mesh(mesh->GetIndices(), mesh->GetType(), newGeom, mesh->GetMaterial(), mesh->GetIndexOffset(), mesh->GetDrawingRange())); }
MeshPtr Translate(MeshPtr mesh, Vector<3, float> move) { GeometrySetPtr newGeom = Translate(mesh->GetGeometrySet(), move); return MeshPtr(new Mesh(mesh->GetIndices(), mesh->GetType(), newGeom, mesh->GetMaterial(), mesh->GetIndexOffset(), mesh->GetDrawingRange())); }
Projectile::Projectile() { // Initialize age to 0 age = 0; // Set default speed speed = glm::vec3(0.0f, 3.0f, 0.0f); rotMomentum = glm::vec3(0.0f, 0.0f, Rand(-PI/4.0f, PI/4.0f)); // Initialize static resources if needed if (!shader) shader = ShaderPtr(new Shader{object_vert, object_frag}); if (!texture) texture = TexturePtr(new Texture{"missile.rgb", 512, 512}); if (!mesh) mesh = MeshPtr(new Mesh{shader, "missile.obj"}); }
Asteroid::Asteroid() { // Reset the age to 0 age = 0; // Set random scale speed and rotation scale *= Rand(1.0f, 3.0f); speed = glm::vec3(Rand(-2.0f, 2.0f), Rand(-5.0f, -10.0f), 0.0f); rotation = glm::vec3(Rand(-PI, PI), Rand(-PI, PI), Rand(-PI, PI)); rotMomentum = glm::vec3(Rand(-PI, PI), Rand(-PI, PI), Rand(-PI, PI)); // Initialize static resources if needed if (!shader) shader = ShaderPtr(new Shader{object_vert, object_frag}); if (!texture) texture = TexturePtr(new Texture{"asteroid.rgb", 512, 512}); if (!mesh) mesh = MeshPtr(new Mesh{shader, "asteroid.obj"}); }
MeshPtr StatefulMeshSerializer::loadMesh(const String& name) { MeshManager* mm = MeshManager::getSingletonPtr(); MeshPtr mesh = mm->create(name, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); mMesh = MeshPtr(new EditableMesh(mm, name, mesh->getHandle(), ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME)); std::ifstream ifs; ifs.open(name.c_str(), std::ios_base::in | std::ios_base::binary); if (!ifs) { throw std::ios_base::failure(("cannot open file " + name).c_str()); } DataStreamPtr stream(new FileStreamDataStream(name, &ifs, false)); determineFileFormat(stream); importMesh(stream, mMesh.getPointer()); ifs.close(); return mMesh; }
MeshPtr MeshUtil::CreateBox() { return MeshPtr(); }
bool pcl::ihs::Integration::reconstructMesh (const CloudXYZRGBNormalConstPtr& cloud_data, MeshPtr& mesh_model) const { if (!cloud_data) { std::cerr << "ERROR in integration.cpp: Cloud pointer is invalid\n"; return (false); } if (!cloud_data->isOrganized ()) { std::cerr << "ERROR in integration.cpp: Cloud is not organized\n"; return (false); } const int width = static_cast <int> (cloud_data->width); const int height = static_cast <int> (cloud_data->height); if (!mesh_model) mesh_model = MeshPtr (new Mesh ()); mesh_model->clear (); mesh_model->reserveVertices (cloud_data->size ()); mesh_model->reserveEdges ((width-1) * height + width * (height-1) + (width-1) * (height-1)); mesh_model->reserveFaces (2 * (width-1) * (height-1)); // Store which vertex is set at which position (initialized with invalid indices) VertexIndices vertex_indices (cloud_data->size (), VertexIndex ()); // Convert to the model cloud type. This is actually not needed but avoids code duplication (see merge). And reconstructMesh is called only the first reconstruction step anyway. // NOTE: The default constructor of PointIHS has to initialize with NaNs! CloudIHSPtr cloud_model (new CloudIHS ()); cloud_model->resize (cloud_data->size ()); // Set the model points not reached by the main loop for (int c=0; c<width; ++c) { const PointXYZRGBNormal& pt_d = cloud_data->operator [] (c); const float weight = -pt_d.normal_z; // weight = -dot (normal, [0; 0; 1]) if (!boost::math::isnan (pt_d.x) && weight > min_weight_) { cloud_model->operator [] (c) = PointIHS (pt_d, weight); } } for (int r=1; r<height; ++r) { for (int c=0; c<2; ++c) { const PointXYZRGBNormal& pt_d = cloud_data->operator [] (r*width + c); const float weight = -pt_d.normal_z; // weight = -dot (normal, [0; 0; 1]) if (!boost::math::isnan (pt_d.x) && weight > min_weight_) { cloud_model->operator [] (r*width + c) = PointIHS (pt_d, weight); } } } // 4 2 - 1 // // | | // // * 3 - 0 // // // // 4 - 2 1 // // \ \ // // * 3 - 0 // const int offset_1 = -width; const int offset_2 = -width - 1; const int offset_3 = - 1; const int offset_4 = -width - 2; for (int r=1; r<height; ++r) { for (int c=2; c<width; ++c) { const int ind_0 = r*width + c; const int ind_1 = ind_0 + offset_1; const int ind_2 = ind_0 + offset_2; const int ind_3 = ind_0 + offset_3; const int ind_4 = ind_0 + offset_4; assert (ind_0 >= 0 && ind_0 < static_cast <int> (cloud_data->size ())); assert (ind_1 >= 0 && ind_1 < static_cast <int> (cloud_data->size ())); assert (ind_2 >= 0 && ind_2 < static_cast <int> (cloud_data->size ())); assert (ind_3 >= 0 && ind_3 < static_cast <int> (cloud_data->size ())); assert (ind_4 >= 0 && ind_4 < static_cast <int> (cloud_data->size ())); const PointXYZRGBNormal& pt_d_0 = cloud_data->operator [] (ind_0); PointIHS& pt_m_0 = cloud_model->operator [] (ind_0); const PointIHS& pt_m_1 = cloud_model->operator [] (ind_1); const PointIHS& pt_m_2 = cloud_model->operator [] (ind_2); const PointIHS& pt_m_3 = cloud_model->operator [] (ind_3); const PointIHS& pt_m_4 = cloud_model->operator [] (ind_4); VertexIndex& vi_0 = vertex_indices [ind_0]; VertexIndex& vi_1 = vertex_indices [ind_1]; VertexIndex& vi_2 = vertex_indices [ind_2]; VertexIndex& vi_3 = vertex_indices [ind_3]; VertexIndex& vi_4 = vertex_indices [ind_4]; const float weight = -pt_d_0.normal_z; // weight = -dot (normal, [0; 0; 1]) if (!boost::math::isnan (pt_d_0.x) && weight > min_weight_) { pt_m_0 = PointIHS (pt_d_0, weight); } this->addToMesh (pt_m_0,pt_m_1,pt_m_2,pt_m_3, vi_0,vi_1,vi_2,vi_3, mesh_model); if (Mesh::IsManifold::value) // Only needed for the manifold mesh { this->addToMesh (pt_m_0,pt_m_2,pt_m_4,pt_m_3, vi_0,vi_2,vi_4,vi_3, mesh_model); } } } return (true); }
void SpriteRenderer::Start() { _mesh = MeshPtr(new Mesh()); GenerateMesh(_mesh.get()); }
MeshWrapper::MeshWrapper(LoaderPtr loader, const std::string &obj_file, const std::string &image_file, int count, glm::vec3 scale) { this->mesh = MeshPtr(new Mesh(loader, obj_file, image_file)); createMatrixes(count, scale); }
MeshInstancePtr MeshInstance::createCompatibleMesh(int vertexCount, GLenum mode, const ShaderPtr& shader) { return MeshInstancePtr(new MeshInstance(mode, MeshPtr(new Mesh(vertexCount, shader->getAttributes())), shader)); }
MeshPtr Mesh::Create(){ MeshPtr ptr = MeshPtr(new Mesh()); ptr->weakPtr = boost::weak_ptr<Mesh>(ptr); return ptr; }
void ScoreWWDCurr(double x1, double y1, double z1, double u, double v, double w, long src, long id) { long wwd, msh, loc0, loc1, ptr; double x0, y0, z0; /* Check if weight windows are used */ if ((long)RDB[DATA_USE_WEIGHT_WINDOWS] == NO) { if (src == NO) Die(FUNCTION_NAME, "Weight windows not in use"); else return; } /* Point before crossing */ x0 = x1 - 2.0*EXTRAP_L*u; y0 = y1 - 2.0*EXTRAP_L*v; z0 = z1 - 2.0*EXTRAP_L*w; /* Pointer to weight window structure */ wwd = (long)RDB[DATA_PTR_WWD0]; CheckPointer(FUNCTION_NAME, "(wwd)", DATA_ARRAY, wwd); /* Loop over structures */ while (wwd > VALID_PTR) { /* Pointer to mesh */ if ((msh = (long)RDB[wwd + WWD_PTR_MESH]) < VALID_PTR) { /* Pointer to next */ wwd = NextItem(wwd); /* Cycle loop */ continue; } /* Check source mode */ if (src == YES) { /* Score source rate (number of particles) */ if ((loc1 = MeshPtr(msh, x1, y1, z1)) > VALID_PTR) { /* Pointer to structure */ loc1 = (long)RDB[loc1]; CheckPointer(FUNCTION_NAME, "(loc1)", DATA_ARRAY, loc1); /* Score */ ptr = (long)RDB[loc1 + WWD_MESH_RES_SRC_RATE]; AddBuf1D(1.0, 1.0, ptr, id, 0); } /* Pointer to next */ wwd = NextItem(wwd); /* Cycle loop */ continue; } /* Score outward current (number of particles) */ if ((loc0 = MeshPtr(msh, x0, y0, z0)) > VALID_PTR) { /* Pointer to structure */ loc0 = (long)RDB[loc0]; CheckPointer(FUNCTION_NAME, "(loc0)", DATA_ARRAY, loc0); /* Score */ ptr = (long)RDB[loc0 + WWD_MESH_RES_OUT_CURR]; AddBuf1D(1.0, 1.0, ptr, id, 0); } /* Score inward current (number of particles) */ if ((loc1 = MeshPtr(msh, x1, y1, z1)) > VALID_PTR) { /* Pointer to structure */ loc1 = (long)RDB[loc1]; CheckPointer(FUNCTION_NAME, "(loc1)", DATA_ARRAY, loc1); /* Score */ ptr = (long)RDB[loc1 + WWD_MESH_RES_IN_CURR]; AddBuf1D(1.0, 1.0, ptr, id, 0); } /* Check */ if ((loc0 > VALID_PTR) && (loc1 > VALID_PTR) && (loc0 != loc1)) { /* Loop over currents */ ptr = (long)RDB[loc0 + WWD_MESH_PTR_CURR]; while (ptr > VALID_PTR) { /* Compare pointers */ if ((long)RDB[ptr + WWD_MESH_CURR_PTR_NEIGHBOUR] == loc1) break; /* Pointer to next */ ptr = NextItem(ptr); } /* Check pointer */ if (ptr < VALID_PTR) Warn(FUNCTION_NAME, "Neighbour cell not found (%E %E %E)", x1, y1, z1); } /* Pointer to next */ wwd = NextItem(wwd); } }
bool EntityGenerate::loadData() { //mParmas["width"] = std::to_string(width); //mParmas["depth"] = std::to_string(depth); //mParmas["m"] = std::to_string(m); //mParmas["n"] = std::to_string(n); if (!mLoaded) { MeshPtr mesh = MeshPtr(new Mesh(mName)); switch (mType) { case Box: { Real width = Commons::toValue<Real>(mParmas["width"]); Real height = Commons::toValue<Real>(mParmas["height"]); Real depth = Commons::toValue<Real>(mParmas["depth"]); GeometryGenerator::createBox(width, height, depth, *mesh); break; } case Sphere: { Real radius = Commons::toValue<Real>(mParmas["radius"]); uint sliceCount = Commons::toValue<uint>(mParmas["sliceCount"]); uint stackCount = Commons::toValue<uint>(mParmas["stackCount"]); GeometryGenerator::createSphere(radius, sliceCount, stackCount, *mesh); break; } case Geosphere: { Real radius = Commons::toValue<Real>(mParmas["radius"]); uint numSubdivisions = Commons::toValue<uint>(mParmas["numSubdivisions"]); GeometryGenerator::createGeosphere(radius, numSubdivisions, *mesh); break; } case Cylinder: { Real bottomRadius = Commons::toValue<Real>(mParmas["bottomRadius"]); Real topRadius = Commons::toValue<Real>(mParmas["topRadius"]); Real height = Commons::toValue<Real>(mParmas["height"]); uint sliceCount = Commons::toValue<uint>(mParmas["sliceCount"]); uint stackCount = Commons::toValue<uint>(mParmas["stackCount"]); GeometryGenerator::createCylinder(bottomRadius, topRadius, height, sliceCount, stackCount, *mesh); break; } case Grid: { Real width = Commons::toValue<Real>(mParmas["width"]); Real depth = Commons::toValue<Real>(mParmas["depth"]); uint m = Commons::toValue<uint>(mParmas["m"]); uint n = Commons::toValue<uint>(mParmas["n"]); GeometryGenerator::createGrid(width, depth, m, n, *mesh); break; } } if (mesh->vertices.size() > 0 && mesh->indices.size() > 0) { mMeshes.push_back(mesh); mLoaded = true; } } return mLoaded; }
long FindPBRegion(long uni0, long pbd, double *x, double *y, double *z, long *pbl0, long *ridx, long id) { long ptr, lst, pbl, uni, ncol, msh; double rp, dx, dy, dz; /* Check pointers */ CheckPointer(FUNCTION_NAME, "(uni0)", DATA_ARRAY, uni0); CheckPointer(FUNCTION_NAME, "(pbd)", DATA_ARRAY, pbd); /* Check plotter mode */ if (((long)RDB[DATA_PLOTTER_MODE] == NO) || ((long)RDB[DATA_QUICK_PLOT_MODE] == YES)) { /* Check previous */ ptr = RDB[uni0 + UNIVERSE_PTR_PREV_REG]; if ((pbl = GetPrivateData(ptr, id)) > VALID_PTR) { /* Get parameters */ dx = *x - RDB[pbl + PEBBLE_X0]; dy = *y - RDB[pbl + PEBBLE_Y0]; dz = *z - RDB[pbl + PEBBLE_Z0]; rp = RDB[pbl + PEBBLE_RAD]; /* Check if particle is inside */ if (dx*dx + dy*dy + dz*dz < rp*rp) { /* Co-ordinate transformation */ *x = dx; *y = dy; *z = dz; /* Get pointer to universe */ uni = (long)RDB[pbl + PEBBLE_PTR_UNIV]; CheckPointer(FUNCTION_NAME, "(uni)", DATA_ARRAY, uni); /* Put pebble pointer */ *pbl0 = pbl; /* Get collision number */ ptr = (long)RDB[DATA_PTR_COLLISION_COUNT]; CheckPointer(FUNCTION_NAME, "(ptr)", PRIVA_ARRAY, ptr); ncol = (long)GetPrivateData(ptr, id); /* Store index */ StoreValuePair(pbd + PBED_PTR_COL_PEBBLE, ncol, (double)pbl, id); /* Put region index */ *ridx = (long)RDB[pbl + PEBBLE_IDX] + 1; /* Return universe pointer */ return uni; } } } /* Reset pebble pointer */ *pbl0 = -1; /* Pointer to search mesh */ msh = (long)RDB[pbd + PBED_PTR_SEARCH_MESH]; CheckPointer(FUNCTION_NAME, "(msh)", DATA_ARRAY, msh); /* Get pointer to search mesh */ if ((lst = MeshPtr(msh, *x, *y, *z)) > VALID_PTR) lst = (long)RDB[lst]; /* Loop over content */ while (lst > VALID_PTR) { /* Pointer to pebble */ pbl = (long)RDB[lst + SEARCH_MESH_CELL_CONTENT]; CheckPointer(FUNCTION_NAME, "(pbl)", DATA_ARRAY, pbl); /* Get parameters */ dx = *x - RDB[pbl + PEBBLE_X0]; dy = *y - RDB[pbl + PEBBLE_Y0]; dz = *z - RDB[pbl + PEBBLE_Z0]; rp = RDB[pbl + PEBBLE_RAD]; /* Check if particle is inside */ if (dx*dx + dy*dy + dz*dz < rp*rp) { /* Co-ordinate transformation */ *x = dx; *y = dy; *z = dz; /* Get pointer to universe */ uni = (long)RDB[pbl + PEBBLE_PTR_UNIV]; CheckPointer(FUNCTION_NAME, "(uni)", DATA_ARRAY, uni); /* Put pebble pointer */ *pbl0 = pbl; /* Get collision number */ ptr = (long)RDB[DATA_PTR_COLLISION_COUNT]; CheckPointer(FUNCTION_NAME, "(ptr)", PRIVA_ARRAY, ptr); ncol = (long)GetPrivateData(ptr, id); /* Store index */ StoreValuePair(pbd + PBED_PTR_COL_PEBBLE, ncol, (double)pbl, id); /* Put region index */ *ridx = (long)RDB[pbl + PEBBLE_IDX] + 1; /* Check plotter mode */ if ((long)RDB[DATA_PLOTTER_MODE] == NO) { /* Pointer to counter */ ptr = (long)RDB[lst + SEARCH_MESH_PTR_CELL_COUNT]; CheckPointer(FUNCTION_NAME, "(ptr)", PRIVA_ARRAY, ptr); /* Add counter */ AddPrivateData(ptr, 1, id); } /* Put previous pointer */ ptr = RDB[uni0 + UNIVERSE_PTR_PREV_REG]; PutPrivateData(ptr, pbl, id); /* Return universe pointer */ return uni; } /* Next */ lst = NextItem(lst); } /* Get pointer to background universe */ uni = (long)RDB[pbd + PBED_PTR_BG_UNIV]; CheckPointer(FUNCTION_NAME, "(uni)", DATA_ARRAY, uni); /* Put region index */ *ridx = 0; /* Return pointer */ return uni; }