Skip to content

Commit

Permalink
tried to add analytic geometry to parametric geometry tool
Browse files Browse the repository at this point in the history
  • Loading branch information
3D-Cave committed Apr 14, 2016
1 parent 2d9ca4a commit 2e4b6c9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/core/objects/geometry/VRHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using namespace OSG;

VRHandle::VRHandle(string name) : VRGeometry(name) {
type = "Handle";
updateCb = VRFunction<int>::create("handle_update", boost::bind(&VRHandle::updateHandle, this) );
setPickable(true);
setPrimitive("Box", "0.1 0.1 0.1 1 1 1");
Expand Down Expand Up @@ -42,7 +43,6 @@ void VRHandle::set(pose p, float v) {
c->toggleTConstraint(0, ptr());
setPose( origin );


if (constraint == LINEAR) {
translate( axis*value*scale );
c->toggleTConstraint(1, ptr());
Expand Down Expand Up @@ -80,7 +80,7 @@ void VRHandle::drop() {
scene->dropUpdateFkt( updateCb );
}

void VRHandle::setMatrix(Matrix m) {
void VRHandle::setMatrix(Matrix m) { // for undo/redo
VRTransform::setMatrix(m);
(*updateCb)(0);
(*updateCb)(0); // problem: called non stop :(
}
1 change: 1 addition & 0 deletions src/core/scripting/VRPyTypeCaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ PyObject* VRPyTypeCaster::cast(OSG::VRObjectPtr obj) {
else if (type == "TextureRenderer") return VRPyTextureRenderer::fromSharedPtr( static_pointer_cast<OSG::VRTextureRenderer>(obj) );
else if (type == "Waypoint") return VRPyWaypoint::fromSharedPtr( static_pointer_cast<OSG::VRWaypoint>(obj) );
else if (type == "JointTool") return VRPyJointTool::fromSharedPtr( static_pointer_cast<OSG::VRJointTool>(obj) );
//else if (type == "Handle") return VRPyHandle::fromSharedPtr( static_pointer_cast<OSG::VRHandle>(obj) );
else if (type == "GeoPrimitive") return VRPyGeoPrimitive::fromSharedPtr( static_pointer_cast<OSG::VRGeoPrimitive>(obj) );
cout << "\nERROR in VRPyTypeCaster::cast: " << type << " not handled!\n";

Expand Down
18 changes: 16 additions & 2 deletions src/core/tools/VRGeoPrimitive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,55 @@
#include "core/utils/toString.h"
#include "core/utils/VRFunction.h"
#include "core/tools/selection/VRSelector.h"
#include "VRAnalyticGeometry.h"

#include <boost/bind.hpp>

using namespace OSG;

VRGeoPrimitive::VRGeoPrimitive(string name) : VRGeometry(name) {
type = "GeoPrimitive";
selector = VRSelector::create();

params_geo = VRAnalyticGeometry::create();
params_geo->setLabelParams(0.05, true, true);
params_geo->setPersistency(0);
}

VRGeoPrimitivePtr VRGeoPrimitive::create(string name) {
auto p = VRGeoPrimitivePtr( new VRGeoPrimitive(name) );
p->addChild(p->params_geo);
p->params_geo->init();
p->setPrimitive("Box");
return p;
}

VRGeoPrimitivePtr VRGeoPrimitive::ptr() { return static_pointer_cast<VRGeoPrimitive>( shared_from_this() ); }

VRAnalyticGeometryPtr VRGeoPrimitive::getLabels() { return params_geo; }

void VRGeoPrimitive::select(bool b) {
if (selected == b) return;
selected = b;
params_geo->setVisible(b);
for (auto h : handles) h->setVisible(b);
if (b) selector->select(ptr(), false);

if (b) selector->select(ptr(), false); // TODO: does not play nice with params_geo!!
else selector->clear();
}

void VRGeoPrimitive::update(int i, float v) {
if (!primitive) return;
auto params = splitString(primitive->toString(), ' ');
string vs = toString(v);
string args;
for (int j=0; j<params.size(); j++) {
if (i != j) args += params[j];
else args += toString(v);
else args += vs;
if (j < params.size()-1) args += " ";
}
VRGeometry::setPrimitive(primitive->getType(), args);
//if (params_geo) params_geo->setVector(i, Vec3f(0,0,0), Vec3f(1,0,0), Vec3f(0.5,0.6,1), vs + " mm"); // TODO: cave crash??
}

void VRGeoPrimitive::setupHandles() {
Expand Down
2 changes: 2 additions & 0 deletions src/core/tools/VRGeoPrimitive.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class VRGeoPrimitive : public VRGeometry {

vector<VRHandlePtr> handles;
VRSelectorPtr selector;
VRAnalyticGeometryPtr params_geo;

void update(int i, float v);
void setupHandles();
Expand All @@ -30,6 +31,7 @@ class VRGeoPrimitive : public VRGeometry {
void select(bool b); // activates editing handles

void setPrimitive(string primitive, string args = ""); // hook on virtual function VRGeometry::setPrimitive
VRAnalyticGeometryPtr getLabels();
};

OSG_END_NAMESPACE;
Expand Down

0 comments on commit 2e4b6c9

Please sign in to comment.