iMSTK
Interactive Medical Simulation Toolkit
imstkVertexPicker.cpp
1 /*
2 ** This file is part of the Interactive Medical Simulation Toolkit (iMSTK)
3 ** iMSTK is distributed under the Apache License, Version 2.0.
4 ** See accompanying NOTICE for details.
5 */
6 
7 #include "imstkVertexPicker.h"
8 #include "imstkImplicitGeometry.h"
9 #include "imstkPointSet.h"
10 #include "imstkVecDataArray.h"
11 
12 namespace imstk
13 {
14 VertexPicker::VertexPicker()
15 {
16  setRequiredInputType<PointSet>(0);
17 }
18 
19 void
21 {
22  auto pointSetToPick = std::dynamic_pointer_cast<PointSet>(getInput(0));
23 
24  // Use implicit functions available in the geometries to sample if in or out of the shape
25  std::shared_ptr<VecDataArray<double, 3>> verticesPtr = pointSetToPick->getVertexPositions();
26  VecDataArray<double, 3>& vertices = *verticesPtr;
27  for (int i = 0; i < vertices.size(); i++)
28  {
29  const double signedDist = m_pickGeometry->getFunctionValue(vertices[i]);
30 
31  // If inside the primitive
32  // \todo: come back to this
33  if (signedDist <= 0.0)
34  {
35  PickData data;
36  data.ids[0] = i;
37  data.idCount = 1;
38  data.cellType = IMSTK_VERTEX;
39  m_results.push_back(data);
40  }
41  }
42 }
43 } // namespace imstk
Base class for all geometries represented by discrete points and elements The pointsets follow a pipe...
Definition: imstkPointSet.h:25
std::shared_ptr< Geometry > getInput(size_t port=0) const
Returns input geometry given port, returns nullptr if doesn&#39;t exist.
void requestUpdate() override
Users can implement this for the logic to be run.
Compound Geometry.
int idCount
Indicates number of vertices (if 1 a cell or individual vertex)
PickData provides ids to indicate what was picked These may be optionally used to indicate the select...
std::shared_ptr< VecDataArray< double, 3 > > getVertexPositions(DataType type=DataType::PostTransform) const
Returns the vector of current positions of the mesh vertices.
CellTypeId cellType
Indicates picked cell type.
int ids[4]
Ids of the cell or vertices.