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)
return;//can't generate a circle in empty space
if(_event->type() == QEvent::MouseMove && createCircle_CurrSelIndex_ != -1) {
PolyLineObject* L = 0;
if(!PluginFunctions::getObject(createCircle_CurrSelIndex_, L))
PolyLineObject* lineObject = 0;
if(!PluginFunctions::getObject(createCircle_CurrSelIndex_, lineObject))
return;
const ACG::Vec3d n = createCircle_Normal_, x0 = createCircle_Point_;
......@@ -908,10 +908,10 @@ me_insertCircle(QMouseEvent* _event)
const double r = d.norm();
const ACG::Vec3d mainAxis = (onPlane - x0).normalize(), sideAxis = (mainAxis % n).normalize();
PolyLineCircleData* LD = new PolyLineCircleData(x0, n, mainAxis, sideAxis, r, r, mesh->id());
L->setObjectData(CIRCLE_DATA, LD);
updatePolyEllipse(L, tool_->sb_CirclePointNum->value());
updateHandles(L);
PolyLineCircleData* lineData = new PolyLineCircleData(x0, n, mainAxis, sideAxis, r, r, mesh->id());
lineObject->setObjectData(CIRCLE_DATA, lineData);
updatePolyEllipse(lineObject, tool_->sb_CirclePointNum->value());
updateHandles(lineObject);
}
else if(_event->type() == QEvent::MouseButtonPress) {
emit addEmptyObject(DATA_POLY_LINE, cur_insert_id_);
......@@ -926,7 +926,7 @@ me_insertCircle(QMouseEvent* _event)
mesh->mesh()->request_face_normals();
createCircle_Normal_ = mesh->mesh()->normal(fh);
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 bbMax(-FLT_MAX,-FLT_MAX,-FLT_MAX);
......@@ -963,11 +963,11 @@ me_insertCircle(QMouseEvent* _event)
emit updatedObject(newLine->id(), UPDATE_ALL);
}
else if(_event->type() == QEvent::MouseButtonRelease) {
PolyLineObject* L;
if(!PluginFunctions::getObject(createCircle_CurrSelIndex_, L))
PolyLineObject* lineObject;
if(!PluginFunctions::getObject(createCircle_CurrSelIndex_, lineObject))
return;
ACG::SceneGraph::GlutPrimitiveNode* N;
if(L->getAdditionalNode(N, name(), "handle0"))
if(lineObject->getAdditionalNode(N, name(), "handle0"))
N->enablePicking(true);
createCircle_CurrSelIndex_ = -1;
}
......@@ -1020,7 +1020,7 @@ me_move( QMouseEvent* _event )
GlutObjectNode* glutNode = dynamic_cast<GlutObjectNode*>(node);
if(glutNode) {
moveCircle_SelNode_ = glutNode;
createCircle_CurrSelIndex_ = glutNode->line->id();
createCircle_LastSelIndex_ = createCircle_CurrSelIndex_ = glutNode->line->id();
}
BaseObjectData* obj = 0;
......@@ -1051,36 +1051,36 @@ me_move( QMouseEvent* _event )
if(moveCircle_SelNode_) {
if(PluginFunctions::scenegraphPick(ACG::SceneGraph::PICK_ANYTHING, _event->pos(), node_idx, target_idx, &hit_point) ) {
PolyLineObject* L;
if(!PluginFunctions::getObject(createCircle_CurrSelIndex_, L))
PolyLineObject* lineObject;
if(!PluginFunctions::getObject(createCircle_CurrSelIndex_, lineObject))
return;
PolyLineCircleData* LD = dynamic_cast<PolyLineCircleData*>(L->objectData(CIRCLE_DATA));
PolyLineCircleData* lineData = dynamic_cast<PolyLineCircleData*>(lineObject->objectData(CIRCLE_DATA));
double cr;
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")) {
LD->circleCenter_ = hit_point;
lineData->circleCenter_ = hit_point;
}
else {
ACG::Vec3d axisa = (onPlane - x0).normalize();
if(!moveCircle_SelNode_->name().compare("N_Handle0")) {
ACG::Vec3d axisb = (axisa % n).normalize();
LD->circleMainRadius_ = cr;
LD->circleMainAxis_ = axisa;
LD->circleSideAxis_ = axisb;
lineData->circleMainRadius_ = cr;
lineData->circleMainAxis_ = axisa;
lineData->circleSideAxis_ = axisb;
} else {
ACG::Vec3d axisb = (n % axisa).normalize();
LD->circleSideRadius_ = cr;
LD->circleSideAxis_ = axisa;
LD->circleMainAxis_ = axisb;
lineData->circleSideRadius_ = cr;
lineData->circleSideAxis_ = axisa;
lineData->circleMainAxis_ = axisb;
}
}
updateHandles(L);
updatePolyEllipse(L, tool_->sb_CirclePointNum->value());
updateHandles(lineObject);
updatePolyEllipse(lineObject, tool_->sb_CirclePointNum->value());
}
}
else if (move_point_ref_ != 0) {
......
......@@ -293,27 +293,37 @@ private:
PolyLine::Point* create_point_ref_;
PolyLine::Point move_point_orig_;
/// 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_Normal_;
/// The handle which is being dragged.
ACG::SceneGraph::GlutPrimitiveNode* moveCircle_SelNode_;
/// Finds the nearest point on the mesh given a point on the normal plane
bool createCircle_getPointOnMesh(TriMeshObject* _triMeshObject,
ACG::Vec3d _center,
ACG::Vec3d _pOnPlane,
ACG::Vec3d _n,
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,
ACG::Vec3d _hit_Point,
ACG::Vec3d* _pOut = 0,
double* _r = 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);
/// Generates points for the ellipse, given the PolyLineObject
void updatePolyEllipse(PolyLineObject* _lineObject, unsigned int _pointCount);
/// updates the center, forward and side handle of the Poly ellipse
void updateHandles(PolyLineObject* _lineObject);
int cur_merge_id_;
......
......@@ -78,22 +78,22 @@ PolyLinePlugin::
createCircle_getPointOnMesh(TriMeshObject* _triMeshObject, ACG::Vec3d _center, ACG::Vec3d _pOnPlane, ACG::Vec3d _n, ACG::Vec3d* _pOut)
{
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;
int i = -1;
double smDist = 10e10;
for(unsigned int j = 0; j < c.size(); j++) {
//ACG::Vec3d norAtInt = M->mesh()->normal(c[j].first);
ACG::Vec3d p = _pOnPlane + _n * c[j].second, dir = _center - p;
for(unsigned int j = 0; j < rayInt.size(); j++) {
ACG::Vec3d norAtInt = _triMeshObject->mesh()->normal(rayInt[j].first);
ACG::Vec3d p = _pOnPlane + _n * rayInt[j].second, dir = _center - p;
const double dist = dir.norm();
if(dist < smDist) {
smDist = dist;
if(_pOut)
*_pOut = p;
*_pOut = p;//+ norAtInt * 0.002;//that would fix lines below the surface, but what is the correct scale?
i = j;
}
}
......@@ -126,11 +126,11 @@ ACG::Vec3d
PolyLinePlugin::
createCircle_getHit(PolyLineCircleData* _circleData, ACG::Vec3d _hit_point)
{
ACG::Vec3d h, p;
ACG::Vec3d pOnMesh, pOnPlane;
double r;
if(!createCircle_getHitInfo(_circleData, _hit_point, &h, &r, &p))
return p;//no point on the mesh was found...
else return h;
if(!createCircle_getHitInfo(_circleData, _hit_point, &pOnMesh, &r, &pOnPlane))
return pOnPlane;//no point on the mesh was found...
else return pOnMesh;
}
//-----------------------------------------------------------------------------
......@@ -153,9 +153,11 @@ updatePolyEllipse(PolyLineObject* _lineObject, unsigned int _pointCount)
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;
const double y = tanTheta_i * x;
ACG::Vec3d p(y,0,x);
if(createCircle_getHitInfo(lineData, basis.toWorld(p) + lineData->circleCenter_, &p))
_lineObject->line()->add_point(p);
ACG::Vec3d pOnMesh;
const ACG::Vec3d pOnPlane(y,0,x),//this is in the local coord system!
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);
}
......@@ -167,7 +169,7 @@ PolyLinePlugin::
slot_setCirclePointNum(int i)
{
PolyLineObject* _lineObject;
if(createCircle_CurrSelIndex_ != -1 && PluginFunctions::getObject(createCircle_CurrSelIndex_, _lineObject))
if(createCircle_LastSelIndex_ != -1 && PluginFunctions::getObject(createCircle_LastSelIndex_, _lineObject))
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