16 #ifndef SURGSIM_BLOCKS_KNOTIDENTIFICATIONBEHAVIOR_H 17 #define SURGSIM_BLOCKS_KNOTIDENTIFICATIONBEHAVIOR_H 23 #include "SurgSim/Framework/Behavior.h" 29 class Fem1DRepresentation;
52 void setFem1d(
const std::shared_ptr<SurgSim::Framework::Component>& fem1d);
55 const std::shared_ptr<SurgSim::Physics::Fem1DRepresentation>& getFem1d()
const;
58 const std::string& getKnotName();
60 void update(
double dt)
override;
61 int getTargetManagerType()
const override;
62 bool doInitialize()
override;
63 bool doWakeUp()
override;
71 void addKnownKnotCode(
const std::string& name,
const std::vector<int>& code,
const std::vector<int>& signs);
74 void clearKnownKnotCodes();
85 double segmentLocation;
87 Crossing(
int id,
size_t segmentId,
double segmentLocation,
int sign)
88 : id(id), segmentId(segmentId), segmentLocation(segmentLocation), sign(sign) {}
89 bool operator==(
const Crossing& rhs)
const 91 return (
id == rhs.
id) && (segmentId == rhs.segmentId) && (segmentLocation == rhs.segmentLocation) &&
98 std::map<std::string, std::vector<std::vector<Crossing>>>
m_knownLists;
116 std::vector<SurgSim::Math::Vector3d>* nodes3d,
117 std::vector<SurgSim::Math::Vector2d>* nodes2d,
118 std::vector<SurgSim::Math::Vector3d>* segments3d);
126 std::vector<Crossing> calculateCrossings(
const Math::Vector3d& projectionZ,
127 const std::vector<SurgSim::Math::Vector3d>& nodes3d,
128 const std::vector<SurgSim::Math::Vector2d>& nodes2d,
129 const std::vector<SurgSim::Math::Vector3d>& segments3d);
133 void performReidmeisterMoves(std::vector<Crossing>* gaussCode);
139 bool tryReidmeisterMove1(std::vector<Crossing>* gaussCode, std::vector<int>* erased);
145 bool tryReidmeisterMove2(std::vector<Crossing>* gaussCode, std::vector<int>* erased);
150 std::vector<Crossing> code;
156 : i(std::numeric_limits<size_t>::max()), iCount(0),
157 m(std::numeric_limits<size_t>::max()), n(std::numeric_limits<size_t>::max()) {}
168 void adjustGaussCodeForErasedCrossings(std::vector<Crossing>* gaussCode);
173 std::string identifyKnot(
const std::vector<Crossing>& gaussCode);
176 std::shared_ptr<SurgSim::Physics::Fem1DRepresentation>
m_fem1d;
191 size_t nextIndex(
const std::vector<Crossing>& code,
size_t i);
196 size_t prevIndex(
const std::vector<Crossing>& code,
size_t i);
201 bool isSameSign(
const std::vector<Crossing>& code,
size_t i,
size_t j);
206 bool isSameCross(
const std::vector<Crossing>& code,
size_t i,
size_t j);
211 bool doesOverlap(
const std::vector<Crossing>& code,
size_t i,
size_t j,
size_t k,
size_t l);
215 void erase(std::vector<Crossing>* code,
size_t i,
size_t j);
219 void erase(std::vector<Crossing>* code,
size_t i,
size_t j,
size_t k,
size_t l);
224 size_t getComplementCross(
const std::vector<Crossing>& code,
size_t i);
231 bool hasCommonNeighbor(
const std::vector<Crossing>& code,
size_t i,
size_t j,
size_t* k,
size_t* l);
235 bool isSameCode(
const std::vector<Crossing>& code,
const std::vector<Crossing>& knot);
241 #endif // SURGSIM_BLOCKS_KNOTIDENTIFICATIONBEHAVIOR_H Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
struct with variables for tracking Reidmeister move 3.
Definition: KnotIdentificationBehavior.h:148
Eigen::Matrix< double, 3, 1 > Vector3d
A 3D vector of doubles.
Definition: Vector.h:57
int sign
also known as handedness. See documentation for addKnownKnotCode.
Definition: KnotIdentificationBehavior.h:86
int id
The gauss code. abs(id) indicates which crossing. sign(id) is positive for over and negative for unde...
Definition: KnotIdentificationBehavior.h:83
struct to store a Crossing.
Definition: KnotIdentificationBehavior.h:80
std::vector< SurgSim::Math::Matrix33d > m_projections
The list of projection matrices to try.
Definition: KnotIdentificationBehavior.h:179
boost::mutex m_mutex
Mutex for the knot name.
Definition: KnotIdentificationBehavior.h:182
Definitions of small fixed-size vector types.
The KnotIdentificationBehavior detects and identifies a knot in a fem1d representation.
Definition: KnotIdentificationBehavior.h:45
Behaviors perform actions.
Definition: Behavior.h:40
std::map< std::string, std::vector< std::vector< Crossing > > > m_knownLists
Known knots, mapping the name to a vector of extended gauss codes.
Definition: KnotIdentificationBehavior.h:98
Eigen::Matrix< double, 3, 3, Eigen::RowMajor > Matrix33d
A 3x3 matrix of doubles.
Definition: Matrix.h:51
std::string m_knotName
The name of the knot that was detected.
Definition: KnotIdentificationBehavior.h:185
std::shared_ptr< SurgSim::Physics::Fem1DRepresentation > m_fem1d
The fem1d within which the knot is checked for.
Definition: KnotIdentificationBehavior.h:176