7 #include "imstkCellPicker.h" 8 #include "imstkAbstractCellMesh.h" 9 #include "imstkCollisionDetectionAlgorithm.h" 10 #include "imstkPointSet.h" 14 CellPicker::CellPicker()
16 setRequiredInputType<Geometry>(0);
27 CHECK(m_colDetect !=
nullptr) <<
"Trying to vertex pick but no collision detection provided";
28 m_colDetect->setInputGeometryA(geomToPick);
29 m_colDetect->setInputGeometryB(m_pickGeometry);
30 m_colDetect->update();
34 if (
auto cellMesh = std::dynamic_pointer_cast<AbstractCellMesh>(geomToPick))
36 cellMesh->computeVertexToCellMap();
40 std::map<int, PickData> resultsMap;
42 const std::vector<CollisionElement>& elementsA = m_colDetect->getCollisionData()->elementsA;
43 for (
size_t i = 0; i < elementsA.size(); i++)
47 if (colElemA.m_type == CollisionElementType::CellIndex)
50 std::copy(colElemA.m_element.m_CellIndexElement.ids,
51 colElemA.m_element.m_CellIndexElement.ids + 4, data.
ids);
52 data.
idCount = colElemA.m_element.m_CellIndexElement.idCount;
53 data.
cellType = colElemA.m_element.m_CellIndexElement.cellType;
54 data.
cellId = colElemA.m_element.m_CellIndexElement.parentId;
55 resultsMap[data.
cellId] = data;
57 else if (colElemA.m_type == CollisionElementType::PointIndexDirection)
59 const int vertexId = colElemA.m_element.m_PointIndexDirectionElement.ptIndex;
63 if (cellMesh !=
nullptr)
65 const std::vector<std::unordered_set<int>>& vertexToCellMap = cellMesh->
getVertexToCellMap();
66 for (
auto cellId : vertexToCellMap[vertexId])
72 const int numComps = cellMesh->getAbstractCells()->getNumberOfComponents();
77 else if (numComps == 2)
81 else if (numComps == 3)
85 else if (numComps == 4)
91 LOG(FATAL) <<
"Unrecognized cell type";
93 resultsMap[cellId] = data;
100 data.
ids[0] = vertexId;
104 m_results.push_back(data);
107 else if (colElemA.m_type == CollisionElementType::PointDirection)
114 data.
pickPoint = colElemA.m_element.m_PointDirectionElement.pt +
115 colElemA.m_element.m_PointDirectionElement.dir *
116 colElemA.m_element.m_PointDirectionElement.penetrationDepth;
117 m_results.push_back(data);
120 for (
auto pickData : resultsMap)
122 m_results.push_back(pickData.second);
std::shared_ptr< Geometry > getInput(size_t port=0) const
Returns input geometry given port, returns nullptr if doesn't exist.
void requestUpdate() override
Users can implement this for the logic to be run.
int idCount
Indicates number of vertices (if 1 a cell or individual vertex)
int cellId
Supplemental cell id (when vertices are provided above and cell id is available)
Vec3d pickPoint
Some pickings may produce specific points on an element.
Union of collision elements. We use a union to avoid polymorphism. There may be many elements and acc...
Base class for any geometrical representation.
PickData provides ids to indicate what was picked These may be optionally used to indicate the select...
const std::vector< std::unordered_set< int > > & getVertexToCellMap() const
Returns map of vertices to cells that contain the vertex (reverse linkage)
CellTypeId cellType
Indicates picked cell type.
Provides non templated base for cell based meshes.
int ids[4]
Ids of the cell or vertices.