OsmMapPtr AlphaShapeGenerator::generateMap(OsmMapPtr inputMap) { boost::shared_ptr<Geometry> cutterShape = generateGeometry(inputMap); if (cutterShape->getArea() == 0.0) { //would rather this be thrown than a warning logged, as the warning may go unoticed by web //clients who are expecting the alpha shape to be generated throw HootException("Alpha Shape area is zero. Try increasing the buffer size and/or alpha."); } OsmMapPtr result; result.reset(new OsmMap(inputMap->getProjection())); // add the resulting alpha shape for debugging. GeometryConverter(result).convertGeometryToElement(cutterShape.get(), Status::Invalid, -1); const RelationMap& rm = result->getRelations(); for (RelationMap::const_iterator it = rm.begin(); it != rm.end(); ++it) { Relation* r = result->getRelation(it->first).get(); r->setTag("area", "yes"); } return result; }
OsmMapPtr AlphaShapeGenerator::generate(OsmMapPtr cutterShapeMap) { MapProjector::projectToPlanar(cutterShapeMap); // put all the nodes into a vector of points. std::vector< std::pair<double, double> > points; points.reserve(cutterShapeMap->getNodeMap().size()); const NodeMap& nodes = cutterShapeMap->getNodeMap(); for (NodeMap::const_iterator it = nodes.begin(); it != nodes.end(); ++it) { pair<double, double> p; p.first = (it->second)->getX(); p.second = (it->second)->getY(); points.push_back(p); } // create a complex geometry representing the alpha shape shared_ptr<Geometry> cutterShape; { AlphaShape alphaShape(_alpha); alphaShape.insert(points); cutterShape = alphaShape.toGeometry(); cutterShape.reset(cutterShape->buffer(_buffer)); } if (cutterShape->getArea() == 0.0) { LOG_WARN("Alpha Shape area is zero. Try increasing the buffer size and/or alpha."); } shared_ptr<OsmMap> result; result.reset(new OsmMap(cutterShapeMap->getProjection())); // add the resulting alpha shape for debugging. GeometryConverter(result).convertGeometryToElement(cutterShape.get(), Status::Invalid, -1); const RelationMap& rm = result->getRelationMap(); for (RelationMap::const_iterator it = rm.begin(); it != rm.end(); ++it) { Relation* r = result->getRelation(it->first).get(); r->setTag("area", "yes"); } return result; }
void FBXScene::ProcessMesh(FbxNode* pNode) { FbxMesh* pFBXMesh = pNode->GetMesh(); if( !pFBXMesh ) return; if ( pFBXMesh->GetPolygonVertexCount() != pFBXMesh->GetPolygonCount() * 3 ) { FbxGeometryConverter GeometryConverter(pNode->GetFbxManager()); if( !GeometryConverter.TriangulateInPlace( pNode ) ) { return; } pFBXMesh = pNode->GetMesh(); } pFBXMesh->InitNormals(); pFBXMesh->ComputeVertexNormals(true); pFBXMesh->GenerateTangentsDataForAllUVSets(); int nVertexCount = pFBXMesh->GetControlPointsCount(); if( nVertexCount <= 0 ) return; std::vector<BoneWeights> boneWeights(nVertexCount); ProcessBoneWeights(pFBXMesh, boneWeights); Model* pModel = new Model(pNode->GetName(), m_Models.GetCount(), false); FbxVector4* aControlPoints = pFBXMesh->GetControlPoints(); for( int pi = 0; pi < pFBXMesh->GetPolygonCount(); ++pi ) // Whole for-loop takes some time too, investigate further. { // Material Material* pMaterial = NULL; for( unsigned int pvi = 0; pvi < 3; ++pvi ) { int nVertexIndex = pFBXMesh->GetPolygonVertex(pi, pvi); if( nVertexIndex < 0 || nVertexIndex >= nVertexCount ) continue; // Material if( pMaterial == NULL ) pMaterial = GetMaterialLinkedWithPolygon(pFBXMesh, 0, pi, 0, nVertexIndex); // Position FbxVector4 fbxPosition = aControlPoints[nVertexIndex]; // Normals And Tangents FbxVector4 fbxNormal, fbxTangent; fbxNormal = GetNormal(pFBXMesh, 0, pi, pvi, nVertexIndex); fbxTangent = GetTangent(pFBXMesh, 0, pi, pvi, nVertexIndex); // Add Vertex pModel->AddVertex(pMaterial, FbxVector4ToBTHFBX_VEC3(fbxPosition), FbxVector4ToBTHFBX_VEC3(fbxNormal), FbxVector4ToBTHFBX_VEC3(fbxTangent), GetTexCoord(pFBXMesh, 0, pi, pvi, nVertexIndex), boneWeights[nVertexIndex]); // Update Bounding Box UpdateBoundingBoxDataFromVertex(FbxVector4ToBTHFBX_VEC3(fbxPosition)); } } // Geometric Offset pModel->SetGeometricOffset2(GetGeometricOffset2(pNode)); // Insert Model m_Models.Add(pModel->GetName(), pModel); }