Commit 2f294c4b authored by Pierre Kraemer's avatar Pierre Kraemer

cell typing in selection algorithms

parent d4a985cf
......@@ -187,12 +187,12 @@ void Surface_Deformation_Plugin::mouseMove(View* view, QMouseEvent* event)
MapHandlerGen* mh = m_schnapps->getSelectedMap();
MapParameters& p = h_parameterSet[mh];
const std::vector<Dart>& handle = p.handleSelector->getSelectedCells();
const std::vector<Vertex>& handle = p.handleSelector->getSelectedCells();
if(!m_draginit)
{
m_dragZ = 0;
for(std::vector<Dart>::const_iterator it = handle.begin(); it != handle.end(); ++it)
for(std::vector<Vertex>::const_iterator it = handle.begin(); it != handle.end(); ++it)
{
const PFP2::VEC3& pp = p.positionAttribute[*it];
qglviewer::Vec q = view->camera()->projectedCoordinatesOf(qglviewer::Vec(pp[0],pp[1],pp[2]));
......@@ -212,7 +212,7 @@ void Surface_Deformation_Plugin::mouseMove(View* view, QMouseEvent* event)
qglviewer::Vec vec = qq - m_dragPrevious;
PFP2::VEC3 t(vec.x, vec.y, vec.z);
for(std::vector<Dart>::const_iterator it = handle.begin(); it != handle.end(); ++it)
for(std::vector<Vertex>::const_iterator it = handle.begin(); it != handle.end(); ++it)
p.positionAttribute[*it] += t;
m_dragPrevious = qq;
......
......@@ -83,9 +83,9 @@ protected:
bool m_selecting;
// cell under the mouse when selecting
Dart m_selectingVertex;
Dart m_selectingEdge;
Dart m_selectingFace;
Vertex m_selectingVertex;
Edge m_selectingEdge;
Face m_selectingFace;
// selecting & selected cells drawing
Utils::PointSprite* m_pointSprite;
......
......@@ -28,50 +28,12 @@ public:
inline const QString& getName() { return m_name; }
inline const std::vector<Dart>& getSelectedCells() { return m_cells; }
virtual inline unsigned int getOrbit() const = 0;
virtual unsigned int getOrbit() = 0;
virtual void select(Dart d, bool emitSignal = true) = 0;
virtual void unselect(Dart d, bool emitSignal = true) = 0;
template <unsigned int ORBIT>
inline void select(const std::vector<Cell<ORBIT> >& d)
{
for(unsigned int i = 0; i < d.size(); ++i)
select(d[i], false);
checkChange();
if(m_isMutuallyExclusive && !m_mutuallyExclusive.empty())
{
foreach(CellSelectorGen* cs, m_mutuallyExclusive)
cs->checkChange();
}
}
template <unsigned int ORBIT>
inline void unselect(const std::vector<Cell<ORBIT> >& d)
{
for(unsigned int i = 0; i < d.size(); ++i)
unselect(d[i], false);
checkChange();
}
virtual bool isSelected(Dart d) = 0;
virtual inline unsigned int getNbSelectedCells() const = 0;
virtual void rebuild() = 0;
inline void setMutuallyExclusive(bool b) { m_isMutuallyExclusive = b; }
inline bool isMutuallyExclusive() const { return m_isMutuallyExclusive; }
inline void setMutuallyExclusiveSet(const QList<CellSelectorGen*>& mex)
{
m_mutuallyExclusive.clear();
foreach(CellSelectorGen* cs, mex)
{
if(cs != this)
m_mutuallyExclusive.append(cs);
}
}
inline void checkChange()
{
if(m_selectionChanged)
......@@ -81,22 +43,25 @@ public:
}
}
inline void setMutuallyExclusive(bool b) { m_isMutuallyExclusive = b; }
inline bool isMutuallyExclusive() const { return m_isMutuallyExclusive; }
virtual inline void setMutuallyExclusiveSet(const QList<CellSelectorGen*>& mex) = 0;
signals:
void selectedCellsChanged();
protected:
QString m_name;
std::vector<Dart> m_cells;
bool m_selectionChanged;
bool m_isMutuallyExclusive;
QList<CellSelectorGen*> m_mutuallyExclusive;
bool m_selectionChanged;
};
template <typename MAP, unsigned int ORBIT>
class CellSelector : public CellSelectorGen
{
typedef Cell<ORBIT> CELL;
typedef CellSelector<MAP, ORBIT> SELECTOR;
public:
CellSelector(MAP& map, const QString& name, unsigned int thread = 0) :
CellSelectorGen(name),
......@@ -107,20 +72,24 @@ public:
~CellSelector()
{}
inline unsigned int getOrbit() { return ORBIT; }
inline unsigned int getOrbit() const { return ORBIT; }
inline const CellMarker<MAP, ORBIT>& getMarker() { return m_cm; }
inline void select(Dart d, bool emitSignal = true)
inline const std::vector<CELL>& getSelectedCells() { return m_cells; }
inline unsigned int getNbSelectedCells() const { return m_cells.size(); }
inline void select(CELL c, bool emitSignal = true)
{
if(!m_cm.isMarked(d))
if(!m_cm.isMarked(c))
{
m_cm.mark(d);
m_cells.push_back(d);
m_cm.mark(c);
m_cells.push_back(c);
if(m_isMutuallyExclusive && !m_mutuallyExclusive.empty())
{
foreach(CellSelectorGen* cs, m_mutuallyExclusive)
cs->unselect(d, emitSignal);
foreach(SELECTOR* cs, m_mutuallyExclusive)
cs->unselect(c, emitSignal);
}
if(emitSignal)
emit(selectedCellsChanged());
......@@ -129,16 +98,28 @@ public:
}
}
inline void unselect(Dart d, bool emitSignal = true)
inline void select(const std::vector<CELL>& c)
{
if(m_cm.isMarked(d))
for(unsigned int i = 0; i < c.size(); ++i)
select(c[i], false);
checkChange();
if(m_isMutuallyExclusive && !m_mutuallyExclusive.empty())
{
unsigned int v = m_map.template getEmbedding<ORBIT>(d);
foreach(SELECTOR* cs, m_mutuallyExclusive)
cs->checkChange();
}
}
inline void unselect(CELL c, bool emitSignal = true)
{
if(m_cm.isMarked(c))
{
unsigned int emb = m_map.getEmbedding(c);
bool found = false;
unsigned int i;
for(i = 0; i < m_cells.size() && !found; ++i)
{
if(m_map.template getEmbedding<ORBIT>(m_cells[i]) == v)
if(m_map.template getEmbedding<ORBIT>(m_cells[i]) == emb)
found = true ;
}
if(found)
......@@ -154,26 +135,50 @@ public:
}
}
inline bool isSelected(Dart d)
inline void unselect(const std::vector<CELL>& c)
{
for(unsigned int i = 0; i < c.size(); ++i)
unselect(c[i], false);
checkChange();
}
inline bool isSelected(CELL c)
{
return m_cm.isMarked(d);
return m_cm.isMarked(c);
}
void rebuild()
{
m_cells.clear();
TraversorCell<MAP, ORBIT> t(m_map, true);
for(Dart d = t.begin(); d != t.end(); d = t.next())
foreach_cell<ORBIT>(m_map, [&] (CELL c)
{
if(m_cm.isMarked(d))
m_cells.push_back(d);
}
if(m_cm.isMarked(c))
m_cells.push_back(c);
});
emit(selectedCellsChanged());
}
inline void setMutuallyExclusiveSet(const QList<CellSelectorGen*>& mex)
{
m_mutuallyExclusive.clear();
foreach(CellSelectorGen* cs, mex)
{
if(cs != this)
{
SELECTOR* s = dynamic_cast<SELECTOR*>(cs);
if (s)
m_mutuallyExclusive.append(s);
}
}
}
private:
MAP& m_map;
CellMarker<MAP, ORBIT> m_cm;
std::vector<CELL> m_cells;
QList<SELECTOR*> m_mutuallyExclusive;
};
} // namespace SCHNApps
......
......@@ -10,8 +10,8 @@ unsigned int CellSelectorGen::selectorCount = 0;
CellSelectorGen::CellSelectorGen(const QString& name) :
m_name(name),
m_selectionChanged(false),
m_isMutuallyExclusive(false)
m_isMutuallyExclusive(false),
m_selectionChanged(false)
{
++selectorCount;
}
......
......@@ -44,7 +44,7 @@ namespace Selection
* @param position the vertex attribute storing positions
* @param rayA first point of ray (user side)
* @param rayAB direction of ray (directed to the scene)
* @param vecFaces (out) vector to store the darts of intersected faces
* @param vecFaces (out) vector to store the intersected faces
* @param iPoints (out) vector to store the intersection points
*/
template<typename PFP>
......@@ -53,7 +53,7 @@ void facesRaySelection(
const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& position,
const typename PFP::VEC3& rayA,
const typename PFP::VEC3& rayAB,
std::vector<Dart>& vecFaces,
std::vector<Face>& vecFaces,
std::vector<typename PFP::VEC3>& iPoints);
/**
......@@ -62,7 +62,7 @@ void facesRaySelection(
* @param position the vertex attribute storing positions
* @param rayA first point of ray (user side)
* @param rayAB direction of ray (directed to the scene)
* @param vecFaces (out) vector to store the darts of intersected faces
* @param vecFaces (out) vector to store the intersected faces
*/
template<typename PFP>
void facesRaySelection(
......@@ -70,7 +70,7 @@ void facesRaySelection(
const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& position,
const typename PFP::VEC3& rayA,
const typename PFP::VEC3& rayAB,
std::vector<Dart>& vecFaces);
std::vector<Face>& vecFaces);
/**
* Function that does the selection of one face
......@@ -78,7 +78,7 @@ void facesRaySelection(
* @param position the vertex attribute storing positions
* @param rayA first point of ray (user side)
* @param rayAB vector of ray (directed ot the scene)
* @param face (out) dart of selected vertex (set to NIL if no face selected)
* @param face (out) selected face (set to NIL if no face selected)
*/
template<typename PFP>
void faceRaySelection(
......@@ -86,7 +86,7 @@ void faceRaySelection(
const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& position,
const typename PFP::VEC3& rayA,
const typename PFP::VEC3& rayAB,
Dart& face);
Face& face);
/**
* Function that does the selection of edges, returned darts are sorted from closest to farthest
......@@ -94,8 +94,8 @@ void faceRaySelection(
* @param position the vertex attribute storing positions
* @param rayA first point of ray (user side)
* @param rayAB vector of ray (directed ot the scene)
* @param vecEdges (out) vector to store dart of intersected edges
* @param dist radius of the cylinder of selection
* @param vecEdges (out) vector to store intersected edges
* @param distMax radius of the cylinder of selection
*/
template<typename PFP>
void edgesRaySelection(
......@@ -103,7 +103,7 @@ void edgesRaySelection(
const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& position,
const typename PFP::VEC3& rayA,
const typename PFP::VEC3& rayAB,
std::vector<Dart>& vecEdges,
std::vector<Edge>& vecEdges,
float distMax);
/**
......@@ -112,7 +112,7 @@ void edgesRaySelection(
* @param position the vertex attribute storing positions
* @param rayA first point of ray (user side)
* @param rayAB vector of ray (directed ot the scene)
* @param edge (out) dart of selected vertex (set to NIL if no edge selected)
* @param edge (out) selected edge (set to NIL if no edge selected)
*/
template<typename PFP>
void edgeRaySelection(
......@@ -120,7 +120,7 @@ void edgeRaySelection(
const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& position,
const typename PFP::VEC3& rayA,
const typename PFP::VEC3& rayAB,
Dart& edge);
Edge& edge);
/**
* Function that does the selection of vertices, returned darts are sorted from closest to farthest
......@@ -128,7 +128,7 @@ void edgeRaySelection(
* @param position the vertex attribute storing positions
* @param rayA first point of ray (user side)
* @param rayAB vector of ray (directed ot the scene)
* @param vecVertices (out) vector to store dart of intersected vertices
* @param vecVertices (out) vector to store intersected vertices
* @param dist radius of the cylinder of selection
*/
template<typename PFP>
......@@ -137,7 +137,8 @@ void verticesRaySelection(
const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& position,
const typename PFP::VEC3& rayA,
const typename PFP::VEC3& rayAB,
std::vector<Dart>& vecVertices);
std::vector<Vertex>& vecVertices,
float dist);
/**
* Function that does the selection of one vertex
......@@ -145,7 +146,7 @@ void verticesRaySelection(
* @param position the vertex attribute storing positions
* @param rayA first point of ray (user side)
* @param rayAB vector of ray (directed ot the scene)
* @param vertex (out) dart of selected vertex (set to NIL if no vertex selected)
* @param vertex (out) selected vertex (set to NIL if no vertex selected)
*/
template<typename PFP>
void vertexRaySelection(
......@@ -153,7 +154,7 @@ void vertexRaySelection(
const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& position,
const typename PFP::VEC3& rayA,
const typename PFP::VEC3& rayAB,
Dart& vertex);
Vertex& vertex);
/**
* Volume selection, not yet functional
......@@ -164,14 +165,14 @@ void volumesRaySelection(
const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& position,
const typename PFP::VEC3& rayA,
const typename PFP::VEC3& rayAB,
std::vector<Dart>& vecVolumes);
std::vector<Vol>& vecVolumes);
template<typename PFP>
void facesPlanSelection(
typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& position,
const typename Geom::Plane3D<typename PFP::VEC3::DATA_TYPE>& plan,
std::vector<Dart>& vecDartss);
std::vector<Face>& vecFaces);
/**
* Function that does the selection of vertices in a cone, returned darts are sorted from closest to farthest
......@@ -179,8 +180,8 @@ void facesPlanSelection(
* @param position the position attribute
* @param rayA first point of ray (user side)
* @param rayAB vector of ray (directed ot the scene)
* @param angle angle of the code in degree.
* @param vecVertices (out) vector to store dart of intersected vertices
* @param angle angle of the cone in degree.
* @param vecVertices (out) vector to store intersected vertices
*/
template<typename PFP>
void verticesConeSelection(
......@@ -188,7 +189,8 @@ void verticesConeSelection(
const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& position,
const typename PFP::VEC3& rayA,
const typename PFP::VEC3& rayAB,
float angle, std::vector<Dart>& vecVertices);
float angle,
std::vector<Vertex>& vecVertices);
/**
* Function that does the selection of edges, returned darts are sorted from closest to farthest
......@@ -197,7 +199,7 @@ void verticesConeSelection(
* @param rayA first point of ray (user side)
* @param rayAB vector of ray (directed ot the scene)
* @param angle radius of the cylinder of selection
* @param vecEdges (out) vector to store dart of intersected edges
* @param vecEdges (out) vector to store intersected edges
*/
template<typename PFP>
void edgesConeSelection(
......@@ -206,7 +208,7 @@ void edgesConeSelection(
const typename PFP::VEC3& rayA,
const typename PFP::VEC3& rayAB,
float angle,
std::vector<Dart>& vecEdges);
std::vector<Edge>& vecEdges);
/**
* Function that select the closest vertex in the bubble
......@@ -216,7 +218,7 @@ void edgesConeSelection(
* @param radiusMax max radius of selection
*/
template<typename PFP>
Dart verticesBubbleSelection(
Vertex verticesBubbleSelection(
typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& position,
const typename PFP::VEC3& cursor,
......@@ -230,7 +232,7 @@ Dart verticesBubbleSelection(
* @param radiusMax max radius of selection
*/
template<typename PFP>
Dart edgesBubbleSelection(
Edge edgesBubbleSelection(
typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& position,
const typename PFP::VEC3& cursor,
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment