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

Hannes update

refs #1730

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@17392 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 50cc4173
...@@ -898,8 +898,8 @@ me_insertCircle(QMouseEvent* _event) ...@@ -898,8 +898,8 @@ me_insertCircle(QMouseEvent* _event)
return;//can't generate a circle in empty space return;//can't generate a circle in empty space
if(_event->type() == QEvent::MouseMove && createCircle_CurrSelIndex_ != -1) { if(_event->type() == QEvent::MouseMove && createCircle_CurrSelIndex_ != -1) {
PolyLineObject* L = 0; PolyLineObject* lineObject = 0;
if(!PluginFunctions::getObject(createCircle_CurrSelIndex_, L)) if(!PluginFunctions::getObject(createCircle_CurrSelIndex_, lineObject))
return; return;
const ACG::Vec3d n = createCircle_Normal_, x0 = createCircle_Point_; const ACG::Vec3d n = createCircle_Normal_, x0 = createCircle_Point_;
...@@ -908,10 +908,10 @@ me_insertCircle(QMouseEvent* _event) ...@@ -908,10 +908,10 @@ me_insertCircle(QMouseEvent* _event)
const double r = d.norm(); const double r = d.norm();
const ACG::Vec3d mainAxis = (onPlane - x0).normalize(), sideAxis = (mainAxis % n).normalize(); const ACG::Vec3d mainAxis = (onPlane - x0).normalize(), sideAxis = (mainAxis % n).normalize();
PolyLineCircleData* LD = new PolyLineCircleData(x0, n, mainAxis, sideAxis, r, r, mesh->id()); PolyLineCircleData* lineData = new PolyLineCircleData(x0, n, mainAxis, sideAxis, r, r, mesh->id());
L->setObjectData(CIRCLE_DATA, LD); lineObject->setObjectData(CIRCLE_DATA, lineData);
updatePolyEllipse(L, tool_->sb_CirclePointNum->value()); updatePolyEllipse(lineObject, tool_->sb_CirclePointNum->value());
updateHandles(L); updateHandles(lineObject);
} }
else if(_event->type() == QEvent::MouseButtonPress) { else if(_event->type() == QEvent::MouseButtonPress) {
emit addEmptyObject(DATA_POLY_LINE, cur_insert_id_); emit addEmptyObject(DATA_POLY_LINE, cur_insert_id_);
...@@ -926,7 +926,7 @@ me_insertCircle(QMouseEvent* _event) ...@@ -926,7 +926,7 @@ me_insertCircle(QMouseEvent* _event)
mesh->mesh()->request_face_normals(); mesh->mesh()->request_face_normals();
createCircle_Normal_ = mesh->mesh()->normal(fh); createCircle_Normal_ = mesh->mesh()->normal(fh);
emit updatedObject(cur_insert_id_, UPDATE_GEOMETRY | UPDATE_TOPOLOGY); emit updatedObject(cur_insert_id_, UPDATE_GEOMETRY | UPDATE_TOPOLOGY);
createCircle_CurrSelIndex_ = newLine->id(); createCircle_LastSelIndex_ = createCircle_CurrSelIndex_ = newLine->id();
ACG::Vec3d bbMin( FLT_MAX, FLT_MAX, FLT_MAX); ACG::Vec3d bbMin( FLT_MAX, FLT_MAX, FLT_MAX);
ACG::Vec3d bbMax(-FLT_MAX,-FLT_MAX,-FLT_MAX); ACG::Vec3d bbMax(-FLT_MAX,-FLT_MAX,-FLT_MAX);
...@@ -963,11 +963,11 @@ me_insertCircle(QMouseEvent* _event) ...@@ -963,11 +963,11 @@ me_insertCircle(QMouseEvent* _event)
emit updatedObject(newLine->id(), UPDATE_ALL); emit updatedObject(newLine->id(), UPDATE_ALL);
} }
else if(_event->type() == QEvent::MouseButtonRelease) { else if(_event->type() == QEvent::MouseButtonRelease) {
PolyLineObject* L; PolyLineObject* lineObject;
if(!PluginFunctions::getObject(createCircle_CurrSelIndex_, L)) if(!PluginFunctions::getObject(createCircle_CurrSelIndex_, lineObject))
return; return;
ACG::SceneGraph::GlutPrimitiveNode* N; ACG::SceneGraph::GlutPrimitiveNode* N;
if(L->getAdditionalNode(N, name(), "handle0")) if(lineObject->getAdditionalNode(N, name(), "handle0"))
N->enablePicking(true); N->enablePicking(true);
createCircle_CurrSelIndex_ = -1; createCircle_CurrSelIndex_ = -1;
} }
...@@ -1020,7 +1020,7 @@ me_move( QMouseEvent* _event ) ...@@ -1020,7 +1020,7 @@ me_move( QMouseEvent* _event )
GlutObjectNode* glutNode = dynamic_cast<GlutObjectNode*>(node); GlutObjectNode* glutNode = dynamic_cast<GlutObjectNode*>(node);
if(glutNode) { if(glutNode) {
moveCircle_SelNode_ = glutNode; moveCircle_SelNode_ = glutNode;
createCircle_CurrSelIndex_ = glutNode->line->id(); createCircle_LastSelIndex_ = createCircle_CurrSelIndex_ = glutNode->line->id();
} }
BaseObjectData* obj = 0; BaseObjectData* obj = 0;
...@@ -1051,36 +1051,36 @@ me_move( QMouseEvent* _event ) ...@@ -1051,36 +1051,36 @@ me_move( QMouseEvent* _event )
if(moveCircle_SelNode_) { if(moveCircle_SelNode_) {
if(PluginFunctions::scenegraphPick(ACG::SceneGraph::PICK_ANYTHING, _event->pos(), node_idx, target_idx, &hit_point) ) { if(PluginFunctions::scenegraphPick(ACG::SceneGraph::PICK_ANYTHING, _event->pos(), node_idx, target_idx, &hit_point) ) {
PolyLineObject* L; PolyLineObject* lineObject;
if(!PluginFunctions::getObject(createCircle_CurrSelIndex_, L)) if(!PluginFunctions::getObject(createCircle_CurrSelIndex_, lineObject))
return; return;
PolyLineCircleData* LD = dynamic_cast<PolyLineCircleData*>(L->objectData(CIRCLE_DATA)); PolyLineCircleData* lineData = dynamic_cast<PolyLineCircleData*>(lineObject->objectData(CIRCLE_DATA));
double cr; double cr;
ACG::Vec3d onPlane; ACG::Vec3d onPlane;
const ACG::Vec3d x0 = LD->circleCenter_, n = LD->circleNormal_; const ACG::Vec3d x0 = lineData->circleCenter_, n = lineData->circleNormal_;
createCircle_getHitInfo(LD, hit_point, &hit_point, &cr, &onPlane); createCircle_getHitInfo(lineData, hit_point, &hit_point, &cr, &onPlane);
if(!moveCircle_SelNode_->name().compare("N_Center")) { if(!moveCircle_SelNode_->name().compare("N_Center")) {
LD->circleCenter_ = hit_point; lineData->circleCenter_ = hit_point;
} }
else { else {
ACG::Vec3d axisa = (onPlane - x0).normalize(); ACG::Vec3d axisa = (onPlane - x0).normalize();
if(!moveCircle_SelNode_->name().compare("N_Handle0")) { if(!moveCircle_SelNode_->name().compare("N_Handle0")) {
ACG::Vec3d axisb = (axisa % n).normalize(); ACG::Vec3d axisb = (axisa % n).normalize();
LD->circleMainRadius_ = cr; lineData->circleMainRadius_ = cr;
LD->circleMainAxis_ = axisa; lineData->circleMainAxis_ = axisa;
LD->circleSideAxis_ = axisb; lineData->circleSideAxis_ = axisb;
} else { } else {
ACG::Vec3d axisb = (n % axisa).normalize(); ACG::Vec3d axisb = (n % axisa).normalize();
LD->circleSideRadius_ = cr; lineData->circleSideRadius_ = cr;
LD->circleSideAxis_ = axisa; lineData->circleSideAxis_ = axisa;
LD->circleMainAxis_ = axisb; lineData->circleMainAxis_ = axisb;
} }
} }
updateHandles(L); updateHandles(lineObject);
updatePolyEllipse(L, tool_->sb_CirclePointNum->value()); updatePolyEllipse(lineObject, tool_->sb_CirclePointNum->value());
} }
} }
else if (move_point_ref_ != 0) { else if (move_point_ref_ != 0) {
......
...@@ -293,27 +293,37 @@ private: ...@@ -293,27 +293,37 @@ private:
PolyLine::Point* create_point_ref_; PolyLine::Point* create_point_ref_;
PolyLine::Point move_point_orig_; PolyLine::Point move_point_orig_;
int createCircle_CurrSelIndex_; /// The object which is being modified(created, dragged)
int createCircle_CurrSelIndex_;
/// Use this one to mark the last index to update the number of points
int createCircle_LastSelIndex_;
/// Data for creating a circle, center and it's normal
ACG::Vec3d createCircle_Point_; ACG::Vec3d createCircle_Point_;
ACG::Vec3d createCircle_Normal_; ACG::Vec3d createCircle_Normal_;
/// The handle which is being dragged.
ACG::SceneGraph::GlutPrimitiveNode* moveCircle_SelNode_; ACG::SceneGraph::GlutPrimitiveNode* moveCircle_SelNode_;
/// Finds the nearest point on the mesh given a point on the normal plane
bool createCircle_getPointOnMesh(TriMeshObject* _triMeshObject, bool createCircle_getPointOnMesh(TriMeshObject* _triMeshObject,
ACG::Vec3d _center, ACG::Vec3d _center,
ACG::Vec3d _pOnPlane, ACG::Vec3d _pOnPlane,
ACG::Vec3d _n, ACG::Vec3d _n,
ACG::Vec3d* _pOut); ACG::Vec3d* _pOut);
/// Calculates common info like point on the mesh, point on the normal plane and the distance from the circle center
bool createCircle_getHitInfo(PolyLineCircleData* _circleData, bool createCircle_getHitInfo(PolyLineCircleData* _circleData,
ACG::Vec3d _hit_Point, ACG::Vec3d _hit_Point,
ACG::Vec3d* _pOut = 0, ACG::Vec3d* _pOut = 0,
double* _r = 0, double* _r = 0,
ACG::Vec3d* _onPlane = 0); ACG::Vec3d* _onPlane = 0);
/// Helper function which returns the point on the mesh or if none could be found the point on the plane
ACG::Vec3d createCircle_getHit(PolyLineCircleData* _circleData, ACG::Vec3d _hit_point); ACG::Vec3d createCircle_getHit(PolyLineCircleData* _circleData, ACG::Vec3d _hit_point);
/// Generates points for the ellipse, given the PolyLineObject
void updatePolyEllipse(PolyLineObject* _lineObject, unsigned int _pointCount); void updatePolyEllipse(PolyLineObject* _lineObject, unsigned int _pointCount);
/// updates the center, forward and side handle of the Poly ellipse
void updateHandles(PolyLineObject* _lineObject); void updateHandles(PolyLineObject* _lineObject);
int cur_merge_id_; int cur_merge_id_;
......
...@@ -78,22 +78,22 @@ PolyLinePlugin:: ...@@ -78,22 +78,22 @@ PolyLinePlugin::
createCircle_getPointOnMesh(TriMeshObject* _triMeshObject, ACG::Vec3d _center, ACG::Vec3d _pOnPlane, ACG::Vec3d _n, ACG::Vec3d* _pOut) createCircle_getPointOnMesh(TriMeshObject* _triMeshObject, ACG::Vec3d _center, ACG::Vec3d _pOnPlane, ACG::Vec3d _n, ACG::Vec3d* _pOut)
{ {
OpenMeshTriangleBSPT<TriMesh>* bsp = _triMeshObject->requestTriangleBsp(); OpenMeshTriangleBSPT<TriMesh>* bsp = _triMeshObject->requestTriangleBsp();
OpenMeshTriangleBSPT<TriMesh>::RayCollision c = bsp->raycollision(_pOnPlane, _n); OpenMeshTriangleBSPT<TriMesh>::RayCollision rayInt = bsp->raycollision(_pOnPlane, _n);
if(c.empty()) if(rayInt.empty())
return false; return false;
int i = -1; int i = -1;
double smDist = 10e10; double smDist = 10e10;
for(unsigned int j = 0; j < c.size(); j++) { for(unsigned int j = 0; j < rayInt.size(); j++) {
//ACG::Vec3d norAtInt = M->mesh()->normal(c[j].first); ACG::Vec3d norAtInt = _triMeshObject->mesh()->normal(rayInt[j].first);
ACG::Vec3d p = _pOnPlane + _n * c[j].second, dir = _center - p; ACG::Vec3d p = _pOnPlane + _n * rayInt[j].second, dir = _center - p;
const double dist = dir.norm(); const double dist = dir.norm();
if(dist < smDist) { if(dist < smDist) {
smDist = dist; smDist = dist;
if(_pOut) if(_pOut)
*_pOut = p; *_pOut = p;//+ norAtInt * 0.002;//that would fix lines below the surface, but what is the correct scale?
i = j; i = j;
} }
} }
...@@ -126,11 +126,11 @@ ACG::Vec3d ...@@ -126,11 +126,11 @@ ACG::Vec3d
PolyLinePlugin:: PolyLinePlugin::
createCircle_getHit(PolyLineCircleData* _circleData, ACG::Vec3d _hit_point) createCircle_getHit(PolyLineCircleData* _circleData, ACG::Vec3d _hit_point)
{ {
ACG::Vec3d h, p; ACG::Vec3d pOnMesh, pOnPlane;
double r; double r;
if(!createCircle_getHitInfo(_circleData, _hit_point, &h, &r, &p)) if(!createCircle_getHitInfo(_circleData, _hit_point, &pOnMesh, &r, &pOnPlane))
return p;//no point on the mesh was found... return pOnPlane;//no point on the mesh was found...
else return h; else return pOnMesh;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
...@@ -153,9 +153,11 @@ updatePolyEllipse(PolyLineObject* _lineObject, unsigned int _pointCount) ...@@ -153,9 +153,11 @@ updatePolyEllipse(PolyLineObject* _lineObject, unsigned int _pointCount)
double x = (r1 * r2) / sqrt(r2 * r2 + r1 * r1 * tanTheta_i * tanTheta_i); double x = (r1 * r2) / sqrt(r2 * r2 + r1 * r1 * tanTheta_i * tanTheta_i);
x = ((theta * i) <= M_PI_2 || (theta * i) > (3.0 * M_PI_2)) ? x : -x; x = ((theta * i) <= M_PI_2 || (theta * i) > (3.0 * M_PI_2)) ? x : -x;
const double y = tanTheta_i * x; const double y = tanTheta_i * x;
ACG::Vec3d p(y,0,x); ACG::Vec3d pOnMesh;
if(createCircle_getHitInfo(lineData, basis.toWorld(p) + lineData->circleCenter_, &p)) const ACG::Vec3d pOnPlane(y,0,x),//this is in the local coord system!
_lineObject->line()->add_point(p); pInWorld = basis.toWorld(pOnPlane) + lineData->circleCenter_;
if(createCircle_getHitInfo(lineData, pInWorld, &pOnMesh))
_lineObject->line()->add_point(pOnMesh);
} }
emit updatedObject(_lineObject->id(), UPDATE_GEOMETRY | UPDATE_TOPOLOGY); emit updatedObject(_lineObject->id(), UPDATE_GEOMETRY | UPDATE_TOPOLOGY);
} }
...@@ -167,7 +169,7 @@ PolyLinePlugin:: ...@@ -167,7 +169,7 @@ PolyLinePlugin::
slot_setCirclePointNum(int i) slot_setCirclePointNum(int i)
{ {
PolyLineObject* _lineObject; PolyLineObject* _lineObject;
if(createCircle_CurrSelIndex_ != -1 && PluginFunctions::getObject(createCircle_CurrSelIndex_, _lineObject)) if(createCircle_LastSelIndex_ != -1 && PluginFunctions::getObject(createCircle_LastSelIndex_, _lineObject))
updatePolyEllipse(_lineObject, i); updatePolyEllipse(_lineObject, i);
} }
......
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