Commit 881a88f5 authored by Jan Möbius's avatar Jan Möbius

Hannes: PolyLine Circles update. TODO: Cleanup variable names!

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@17375 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 8074fbe9
This diff is collapsed.
......@@ -43,6 +43,10 @@
#include <ObjectTypes/Plane/QtPlaneSelect.hh>
#include <ACG/Scenegraph/GlutPrimitiveNode.hh>
#include <ObjectTypes/PolyLine/PolyLineCircleData.hh>
#define CREATE_CUT_POLYLINE "Create Polyline"
//== CLASS DEFINITION =========================================================
......@@ -174,18 +178,20 @@ private slots:
void slot_smart_move_timer();
void slot_setCirclePointNum(int i);
private :
EditMode mode();
// mouse events
void me_insert ( QMouseEvent* _event );
void me_insertCircle(QMouseEvent* _event );
void me_delete ( QMouseEvent* _event );
void me_move ( QMouseEvent* _event );
void me_split ( QMouseEvent* _event );
void me_merge ( QMouseEvent* _event );
void me_smart_move( QMouseEvent* _event );
void me_insert ( QMouseEvent* _event );
void me_insertCircle( QMouseEvent* _event );
void me_delete ( QMouseEvent* _event );
void me_move ( QMouseEvent* _event );
void me_split ( QMouseEvent* _event );
void me_merge ( QMouseEvent* _event );
void me_smart_move ( QMouseEvent* _event );
//===========================================================================
/** @name ToolBox
......@@ -227,13 +233,13 @@ private :
QActionGroup* pickToolBarActions_;
QAction* insertAction_;
QAction* insertCircleAction_;
QAction* deleteAction_;
QAction* moveAction_;
QAction* smartMoveAction_;
QAction* mergeAction_;
QAction* splitAction_;
QAction* cutAction_;
QAction* insertCircleAction_;
private slots:
......@@ -287,9 +293,28 @@ private:
PolyLine::Point* create_point_ref_;
PolyLine::Point move_point_orig_;
bool createCircle_Active_;
int createCircle_CurrSelIndex_;
ACG::Vec3d createCircle_Point_;
ACG::Vec3d createCircle_Normal;
ACG::Vec3d createCircle_Normal_;
ACG::SceneGraph::GlutPrimitiveNode* moveCircle_SelNode_;
bool createCircle_getPointOnMesh(TriMeshObject* _triMeshObject,
ACG::Vec3d _center,
ACG::Vec3d _pOnPlane,
ACG::Vec3d _n,
ACG::Vec3d* _pOut);
bool createCircle_getHitInfo(PolyLineCircleData* _circleData,
ACG::Vec3d _hit_Point,
ACG::Vec3d* _pOut = 0,
double* _r = 0,
ACG::Vec3d* _onPlane = 0);
ACG::Vec3d createCircle_getHit(PolyLineCircleData* _circleData, ACG::Vec3d _hit_point);
void updatePolyEllipse(PolyLineObject* _lineObject, unsigned int _pointCount);
void updateHandles(PolyLineObject* _lineObject);
int cur_merge_id_;
......
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenFlipper. *
* *
* OpenFlipper is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenFlipper is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision$ *
* $Author$ *
* $Date$ *
* *
\*===========================================================================*/
//=============================================================================
//
// CLASS PolyLinePlugin - IMPLEMENTATION
//
//=============================================================================
//== INCLUDES =================================================================
#include "PolyLinePlugin.hh"
namespace {
struct Onb {
ACG::Vec3d x,y,z;
Onb(PolyLineCircleData* _circleData) {
x = _circleData->circleMainAxis_;
z = _circleData->circleSideAxis_;
y = _circleData->circleNormal_;
}
ACG::Vec3d toWorld(ACG::Vec3d v) const {
return ACG::Vec3d(x[0] * v[0] + y[0] * v[1] + z[0] * v[2],
x[1] * v[0] + y[1] * v[1] + z[1] * v[2],
x[2] * v[0] + y[2] * v[1] + z[2] * v[2]);
}
};
}
//-----------------------------------------------------------------------------
bool
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);
if(c.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;
double dist = sqrt(dir | dir);
if(dist < smDist) {
smDist = dist;
if(_pOut)
*_pOut = p;
i = j;
}
}
return i != -1;
}
//-----------------------------------------------------------------------------
bool
PolyLinePlugin::
createCircle_getHitInfo(PolyLineCircleData* _circleData, ACG::Vec3d _hit_Point, ACG::Vec3d* _pOut, double* r, ACG::Vec3d* _onPlaneO)
{
ACG::Vec3d n = _circleData->circleNormal_, x0 = _circleData->circleCenter_;
double t = ((n | x0) - (n | _hit_Point)) / (n | n);
ACG::Vec3d onPlane = _hit_Point + t * n, d = onPlane - x0;
if(r)
*r = d.norm();
if(_onPlaneO)
*_onPlaneO = onPlane;
TriMeshObject* mesh;
if(PluginFunctions::getObject(_circleData->circleMeshIndex_, mesh))
return createCircle_getPointOnMesh(mesh, x0, onPlane, n, _pOut);
else return false;
}
//-----------------------------------------------------------------------------
ACG::Vec3d
PolyLinePlugin::
createCircle_getHit(PolyLineCircleData* _circleData, ACG::Vec3d _hit_point)
{
ACG::Vec3d h, p;
double r;
if(!createCircle_getHitInfo(_circleData, _hit_point, &h, &r, &p))
return p;//no point on the mesh was found...
else return h;
}
//-----------------------------------------------------------------------------
void
PolyLinePlugin::
updatePolyEllipse(PolyLineObject* _lineObject, unsigned int _pointCount)
{
PolyLineCircleData* lineData = dynamic_cast<PolyLineCircleData*>(_lineObject->objectData(CIRCLE_DATA));
const double theta = 2.0 * M_PI / double(_pointCount);
_pointCount += tool_->rb_CloseCircle->isChecked() ? 0 : -1;
const double r2 = lineData->circleMainRadius_, r1 = lineData->circleSideRadius_;
const Onb basis(lineData);
_lineObject->line()->clear();
for(unsigned int i = 0; i <= _pointCount; i++) {
const double tanTheta_i = tan(theta * 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;
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);
}
emit updatedObject(_lineObject->id(), UPDATE_GEOMETRY | UPDATE_TOPOLOGY);
}
//-----------------------------------------------------------------------------
void
PolyLinePlugin::
slot_setCirclePointNum(int i)
{
PolyLineObject* _lineObject;
if(createCircle_CurrSelIndex_ != -1 && PluginFunctions::getObject(createCircle_CurrSelIndex_, _lineObject))
updatePolyEllipse(_lineObject, i);
}
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>388</width>
<height>713</height>
<width>363</width>
<height>741</height>
</rect>
</property>
<property name="sizePolicy">
......@@ -519,6 +519,43 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_4">
<property name="title">
<string>Poly Lines</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QRadioButton" name="rb_CloseCircle">
<property name="text">
<string>Close Poly Circles</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Number Circle Points</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="sb_CirclePointNum">
<property name="value">
<number>16</number>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
......@@ -526,8 +563,8 @@
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
......
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