Commit 8d6d13f8 authored by Jan Möbius's avatar Jan Möbius

Generate multiple polylines on plane cuts


git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@20814 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 8295d5d6
......@@ -226,7 +226,7 @@ slotMouseEvent( QMouseEvent* _event )
default:
break;
}
} else if (PluginFunctions::pickMode() == CREATE_CUT_POLYLINE) {
} else if ( (PluginFunctions::pickMode() == CREATE_CUT_POLYLINE) || (PluginFunctions::pickMode() == CREATE_CUT_POLYLINES) ) {
planeSelect_->slotMouseEvent(_event);
}
}
......@@ -266,6 +266,7 @@ slotPickModeChanged( const std::string& _mode)
{
polyLineAction_->setChecked(_mode == "PolyLine");
cutAction_->setChecked( _mode == CREATE_CUT_POLYLINE );
cutMultipleAction_->setChecked( _mode == CREATE_CUT_POLYLINES );
}
......@@ -280,6 +281,7 @@ pluginsInitialized()
emit addHiddenPickMode("PolyLine");
emit setPickModeMouseTracking("PolyLine", true);
emit addHiddenPickMode( CREATE_CUT_POLYLINE );
emit addHiddenPickMode( CREATE_CUT_POLYLINES );
emit registerKey(Qt::Key_Return, Qt::NoModifier, tr("Terminate creation of poly line."), true);
emit registerKey(Qt::Key_Return, Qt::ShiftModifier, tr("Terminate creation of poly line and create loop."), true);
......@@ -306,6 +308,14 @@ pluginsInitialized()
connect(cutAction_, SIGNAL(triggered()), this, SLOT(slotScissorButton()) );
toolbar_->addAction(cutAction_);
// icon for polyline cutting of objects
cutMultipleAction_ = new QAction(tr("&Create polylines at intersection with plane"), this);
cutMultipleAction_->setCheckable( true );
cutMultipleAction_->setStatusTip(tr("Create polylines by specifying a plane with which the object is then intersected. The polylines will be created at the intersection."));
cutMultipleAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"cut_polylines.png") );
connect(cutMultipleAction_, SIGNAL(triggered()), this, SLOT(slotScissorLinesButton()) );
toolbar_->addAction(cutMultipleAction_);
connect(toolBarActions_, SIGNAL(triggered(QAction*)), this, SLOT(slotSetPolyLineMode(QAction*)) );
emit addToolbar(toolbar_);
......@@ -416,6 +426,17 @@ void PolyLinePlugin::slotScissorButton( )
PluginFunctions::pickMode( CREATE_CUT_POLYLINE );
}
//------------------------------------------------------------------------------
/** \brief Scissor Button was hit
*
*/
void PolyLinePlugin::slotScissorLinesButton( )
{
PluginFunctions::actionMode( Viewer::PickingMode );
PluginFunctions::pickMode( CREATE_CUT_POLYLINES );
}
//-----------------------------------------------------------------------------
/** \brief Generate PolyLine after the cutPlane has been drawn
......@@ -423,7 +444,8 @@ void PolyLinePlugin::slotScissorButton( )
*/
void PolyLinePlugin::slotTriggerCutPlaneSelect( )
{
using ACG::SceneGraph::LineNode;
using ACG::SceneGraph::LineNode;
// Iterate over all selected objects
BaseObjectData* object;
......@@ -438,25 +460,50 @@ void PolyLinePlugin::slotTriggerCutPlaneSelect( )
ACG::Vec3d point = planeSelect_->getSourcePoint();
ACG::Vec3d normal = planeSelect_->getNormal();
int objectId = generatePolyLineFromCut(object->id(), point, normal);
if ( PluginFunctions::pickMode() == CREATE_CUT_POLYLINE) {
int objectId = generatePolyLineFromCut(object->id(), point, normal);
QString command = "generatePolyLineFromCut(" + QString::number(object->id()) + ",Vector("
+ QString::number(point[0]) + "," + QString::number(point[1]) + "," + QString::number(point[2]) + "),Vector("
+ QString::number(normal[0]) + "," + QString::number(normal[1]) + "," + QString::number(normal[2]) + "));";
emit scriptInfo(command);
QString command = "generatePolyLineFromCut(" + QString::number(object->id()) + ",Vector("
+ QString::number(point[0]) + "," + QString::number(point[1]) + "," + QString::number(point[2]) + "),Vector("
+ QString::number(normal[0]) + "," + QString::number(normal[1]) + "," + QString::number(normal[2]) + "));";
emit scriptInfo(command);
//remove all other targets
for (PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS,
DataType(DATA_TRIANGLE_MESH | DATA_POLY_MESH)); o_it != PluginFunctions::objectsEnd(); ++o_it) {
if (o_it->id() != object->id()) {
o_it->target(false);
//remove all other targets
for (PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS,
DataType(DATA_TRIANGLE_MESH | DATA_POLY_MESH)); o_it != PluginFunctions::objectsEnd(); ++o_it) {
if (o_it->id() != object->id()) {
o_it->target(false);
}
}
}
// If we successfully created the polyline, we can inform the core about it.
if ( objectId != -1)
emit updatedObject(objectId,UPDATE_ALL);
// If we successfully created the polyline, we can inform the core about it.
if ( objectId != -1)
emit updatedObject(objectId,UPDATE_ALL);
} else {
std::vector <int> objectIds = generatePolyLinesFromCut(object->id(), point, normal);
QString command = "generatePolyLinesFromCut(" + QString::number(object->id()) + ",Vector("
+ QString::number(point[0]) + "," + QString::number(point[1]) + "," + QString::number(point[2]) + "),Vector("
+ QString::number(normal[0]) + "," + QString::number(normal[1]) + "," + QString::number(normal[2]) + "));";
emit scriptInfo(command);
//remove all other targets
for (PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS,
DataType(DATA_TRIANGLE_MESH | DATA_POLY_MESH)); o_it != PluginFunctions::objectsEnd(); ++o_it) {
if (o_it->id() != object->id()) {
o_it->target(false);
}
}
for ( unsigned int i = 0 ; i < objectIds.size() ; ++i ) {
// If we successfully created the polyline, we can inform the core about it.
if ( objectIds[i] != -1)
emit updatedObject(objectIds[i],UPDATE_ALL);
}
}
}
}
......@@ -2048,8 +2095,6 @@ void
PolyLinePlugin::
slotEnablePickMode(QString _name)
{
std::cerr << "slotEnablePickMode\n";
PluginFunctions::pickMode("PolyLine");
PluginFunctions::actionMode(Viewer::PickingMode);
......
......@@ -50,6 +50,7 @@
#include <ObjectTypes/PolyLine/PolyLineBezierSplineData.hh>
#define CREATE_CUT_POLYLINE "Create Polyline"
#define CREATE_CUT_POLYLINES "Create Polylines"
//== CLASS DEFINITION =========================================================
......@@ -241,6 +242,9 @@ private :
/// Called by Toolbar to enable pick mode
void slotSetPolyLineMode(QAction* _action);
/// Called by Toolbar to enable pick mode
void slotSetPolyLinesMode(QAction* _action);
/** @} */
//===========================================================================
......@@ -261,6 +265,7 @@ private :
QAction* mergeAction_;
QAction* splitAction_;
QAction* cutAction_;
QAction* cutMultipleAction_;
private slots:
......@@ -276,11 +281,15 @@ private :
private:
/// get the points from the intersection between mesh and plane
/// get the points from the closest connected intersection between mesh and plane
template< class MeshT > std::vector< ACG::Vec3d >
getIntersectionPoints ( MeshT* _mesh, uint _fh, ACG::Vec3d _planeNormal ,
ACG::Vec3d _planePoint, bool& _closed );
/// get all points from the intersection between mesh and plane
template< class MeshT > std::vector< std::vector< ACG::Vec3d > >
getMultipleIntersectionPoints( MeshT* _mesh, ACG::Vec3d _planeNormal , ACG::Vec3d _planePoint );
/// get an edge of the mesh that is cut by the plane
template< class MeshT >
typename MeshT::EdgeHandle
......@@ -297,11 +306,17 @@ public slots:
/// Generates a polyLine of a plane intersection
int generatePolyLineFromCut( int _objectId, Vector _planePoint, Vector _planeNormal, int _polyLineId = -1 );
/// Generates a polyLine of a plane intersection
std::vector<int> generatePolyLinesFromCut( int _objectId, Vector _planePoint, Vector _planeNormal );
private slots:
/// Scissor Button was hit
void slotScissorButton();
/// Scissor Button for multiple polylines was hit
void slotScissorLinesButton();
/// Generate PolyLine after the cutPlane has been drawn
void slotTriggerCutPlaneSelect();
......
This diff is collapsed.
......@@ -109,3 +109,98 @@ int PolyLinePlugin::generatePolyLineFromCut( int _objectId, Vector _planePoint,
return polyLineId;
}
/** \brief Generates polyLines from a plane intersection
*
*
* @param _objectId id of the target object
* @param _planePoint a point on the cut plane
* @param _planeNormal the normal of the cut plane
* @return returns the ids of the polyLine
*/
std::vector<int> PolyLinePlugin::generatePolyLinesFromCut( int _objectId, Vector _planePoint, Vector _planeNormal) {
// List of generated lines
std::vector<int> lines;
// get object
BaseObjectData *obj;
PluginFunctions::getObject(_objectId, obj);
if (obj == 0){
emit log(LOGERR,tr("Unable to get object"));
return lines;
}
//get the intersection points
std::vector< std::vector< ACG::Vec3d > > linePoints;
bool closed = false;
if ( obj->dataType(DATA_TRIANGLE_MESH) ) {
TriMesh* mesh = PluginFunctions::triMesh(obj);
if ( mesh == 0 ) {
emit log(LOGERR,tr("Unable to get mesh"));
return lines;
}
// get all intersection points
linePoints = getMultipleIntersectionPoints( mesh, _planeNormal , _planePoint);
} else {
PolyMesh* mesh = PluginFunctions::polyMesh(obj);
if ( mesh == 0 ) {
emit log(LOGERR,tr("Unable to get mesh"));
return lines;
}
// get all intersection points
linePoints = getMultipleIntersectionPoints( mesh, _planeNormal , _planePoint);
}
// No lines found?
if ( linePoints.empty() ) {
emit log(LOGERR,tr("No cut lines found."));
return lines;
}
for ( unsigned int i = 0 ; i < linePoints.size(); ++i ) {
if ( linePoints[i].empty() )
continue;
//generate a polyLine from the intersection Points
int polyLineId = -1;
// add new polyline
emit addEmptyObject(DATA_POLY_LINE,polyLineId);
// get current polylineobject
BaseObjectData *polyLineObj;
PluginFunctions::getObject(polyLineId, polyLineObj);
// get polyline object
PolyLineObject* currentPolyLine = PluginFunctions::polyLineObject(polyLineObj);
currentPolyLine->line()->clear();
for ( unsigned int j = 0 ; j < linePoints[i].size(); ++j )
currentPolyLine->line()->add_point( (PolyLine::Point) linePoints[i][j] );
currentPolyLine->line()->set_closed(closed);
currentPolyLine->target(true);
lines.push_back(polyLineId);
}
return lines;
}
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