コード例 #1
0
ファイル: ScaleAxisArrow.cpp プロジェクト: dewf/mrLab3d
static SoSeparator *arrowGeom(ScaleAxisArrow::AxisEnum axis, SoScale *antiScale, bool mirrored)
{
	SoSeparator *root = new SoSeparator();

    SoText2 *label = new SoText2();
    label->justification = SoText2::CENTER;
    if (axis == ScaleAxisArrow::AXIS_X) {
        label->string.setValue(mirrored ? "-X" : "+X");
    } else if (axis == ScaleAxisArrow::AXIS_Y) {
        label->string.setValue(mirrored ? "-Y" : "+Y");
    } else if (axis == ScaleAxisArrow::AXIS_Z) {
        label->string.setValue(mirrored ? "-Z" : "+Z");
    }

	float mul = mirrored ? -1.0f : 1.0f;

    // lines
    float verts[][3] = {
            // from origin to bottom of cone
            {0, 0, 0},
            {0, mul * CUBE_OFFS, 0},
    };
    SoCoordinate3 *coords = new SoCoordinate3();
    coords->point.setValues(0, 2, verts);
    root->addChild(coords);

    int indices[] = {
            0, 1, SO_END_LINE_INDEX,
    };
    SoIndexedLineSet *lines = new SoIndexedLineSet();
    lines->coordIndex.setValues(0, 3, indices);
    root->addChild(lines);

	// cube translation
    SoTranslation *xlat = new SoTranslation();
    xlat->translation.setValue(0, mul * CUBE_OFFS, 0);
    root->addChild(xlat);

	// to keep the cubes from scaling (ultimately handled/set by parent ScaleWidget)
	root->addChild(antiScale);

	SoCube *cube = new SoCube();
	cube->width = cube->height = cube->depth = 0.35;
	root->addChild(cube);

	// axis label translation
    SoTranslation *xlat2 = new SoTranslation();
    xlat2->translation.setValue(0, mul * (CUBE_HEIGHT/2+0.2), 0);
    root->addChild(xlat2);

    root->addChild(label);

	return root;
}
コード例 #2
0
ファイル: coloreditor.cpp プロジェクト: ruisebastiao/SoQt
int
main(int argc, char ** argv)
{
  QWidget * w = SoQt::init(argc, argv, "SoQtColorEditor");
  SoQtExaminerViewer * viewer = new SoQtExaminerViewer(w);
  SoSeparator * root;
  viewer->setSceneGraph(root = makescene());
  viewer->show();

  // we want ColorEditor in scene
  SoSeparator * editorscene = new SoSeparator;
  SoTranslation * trans = new SoTranslation;
  trans->translation.setValue(SbVec3f(2.0f, 0.0f, 0.0f));
  SoRotationXYZ * rot = new SoRotationXYZ;
  SoMaterial * mat = new SoMaterial;
  mat->diffuseColor.setValue(0.8, 0.8, 0.8);
  rot->axis = SoRotationXYZ::Y;
  rot->angle = 0.5;
  editorscene->addChild(trans);
  editorscene->addChild(rot);
  editorscene->addChild(mat);
  SoGuiColorEditor * inscene = new SoGuiColorEditor;
  inscene->wysiwyg.setValue(TRUE);
  inscene->color.connectFrom(&(material->diffuseColor));
  inscene->color.getValue(); // update field
  material->diffuseColor.connectFrom(&(inscene->color));
  editorscene->addChild(inscene);
  root->insertChild(editorscene, 0);

#if 0
  SoQtColorEditor * editor = new SoQtColorEditor;
  editor->attach(&(material->diffuseColor));
  editor->show();
#endif

  SoQt::show(w);
  SoQt::mainLoop();
  return 0;
}
コード例 #3
0
ファイル: main_test_app.cpp プロジェクト: hardegg/aflw
  int
  main(int argc, char ** argv)
  {
    QApplication app(argc, argv);
    // Initializes Quarter library (and implicitly also the Coin and Qt
    // libraries).
    Quarter::init();

    // Make a dead simple scene graph by using the Coin library, only
    // containing a single yellow cone under the scenegraph root.
    SoSeparator * root = new SoSeparator;
    root->ref();

    SoBaseColor * col = new SoBaseColor;
    col->rgb = SbColor(1, 1, 0);
    root->addChild(col);

    root->addChild(new SoCone);

    // Create a QuarterWidget for displaying a Coin scene graph
    QuarterWidget * viewer = new QuarterWidget;
    viewer->setSceneGraph(root);

    // make the viewer react to input events similar to the good old
    // ExaminerViewer
    viewer->setNavigationModeFile(QUrl("coin:///scxml/navigation/examiner.xml"));

    // Pop up the QuarterWidget
    viewer->show();
    // Loop until exit.
    app.exec();
    // Clean up resources.
    root->unref();
    delete viewer;

    Quarter::clean();

    return 0;
  }
コード例 #4
0
VirtualRobot::VisualizationNodePtr CoinVisualizationNode::clone(bool deepCopy, float scaling)
{
	THROW_VR_EXCEPTION_IF(scaling<=0,"Scaling must be >0");

	SoSeparator* newModel = NULL;
	if (visualization)
	{
		newModel = new SoSeparator;
		newModel->ref();
		if (scaling!=1.0)
		{
			SoScale *s = new SoScale;
			s->scaleFactor.setValue(scaling,scaling,scaling);
			newModel->addChild(s);
		}
		if (deepCopy)
		{
			newModel->addChild(visualization->copy(FALSE));
		} else
			newModel->addChild(visualization);
	}
	VisualizationNodePtr p(new CoinVisualizationNode(newModel));
	if (newModel)
		newModel->unrefNoDelete();
	p->setUpdateVisualization(updateVisualization);
	p->setGlobalPose(getGlobalPose());
	p->setFilename(filename,boundingBox);

	// clone attached visualizations
	std::map< std::string, VisualizationNodePtr >::const_iterator i = attachedVisualizations.begin();
	while (i!=attachedVisualizations.end())
	{
		VisualizationNodePtr attachedClone = i->second->clone(deepCopy,scaling);
		p->attachVisualization(i->first, attachedClone);
		i++;
	}

	return p;
}
コード例 #5
0
SoSeparator*
VirtualContact::getVisualIndicator()
{
    SoTransform *tran;

    //this one is a member variable so we can change color if we want to "mark" the contact
    if (!mZaxisMat) {
        mZaxisMat = new SoMaterial;
        mZaxisMat->ref();
    }
    mZaxisMat->diffuseColor = SbColor(0.8f,0,0);
    mZaxisMat->ambientColor = SbColor(0.8f,0,0);

    tran = new SoTransform;
    getContactFrame().toSoTransform(tran);

    SoCylinder *zaxisCyl = new SoCylinder;
    zaxisCyl->radius = 0.2f;
    zaxisCyl->height = Body::CONE_HEIGHT;

    SoSphere *zaxisSphere = new SoSphere;
    zaxisSphere->radius = 3.0f;

    SoTransform *zaxisTran = new SoTransform;
    zaxisTran->translation.setValue(0,0,Body::CONE_HEIGHT/2.0);
//	zaxisTran->translation.setValue(0,0,2.0);
    zaxisTran->rotation.setValue(SbVec3f(1,0,0),(float)M_PI/2.0f);

    SoSeparator *zaxisSep = new SoSeparator;
    zaxisSep->addChild(zaxisTran);
    zaxisSep->addChild(mZaxisMat);
    zaxisSep->addChild(zaxisCyl);
//	zaxisSep->addChild(zaxisSphere);

    SoSeparator* cne = new SoSeparator;
    cne->addChild(tran);
    cne->addChild(zaxisSep);
    return cne;
}
コード例 #6
0
void
SoXipOverlayTransformBoxManip::create()
{
	mControlPointsCoords = new SoCoordinate3;
	mControlPointsCoords->point.setNum(8);
	mControlPointsCoords->point.set1Value( 0, SbVec3f( -0.5,  0.5, 0 ) );
	mControlPointsCoords->point.set1Value( 1, SbVec3f(    0,  0.5, 0 ) );
	mControlPointsCoords->point.set1Value( 2, SbVec3f(  0.5,  0.5, 0 ) );
	mControlPointsCoords->point.set1Value( 3, SbVec3f(  0.5,    0, 0 ) );
	mControlPointsCoords->point.set1Value( 4, SbVec3f(  0.5, -0.5, 0 ) );
	mControlPointsCoords->point.set1Value( 5, SbVec3f(    0, -0.5, 0 ) );
	mControlPointsCoords->point.set1Value( 6, SbVec3f( -0.5, -0.5, 0 ) );
	mControlPointsCoords->point.set1Value( 7, SbVec3f( -0.5,    0, 0 ) );

	mControlPointsStyle = new SoDrawStyle;
	mControlPointsStyle->pointSize.setValue(5);
	mControlPointsStyle->lineWidth.setValue(1);

	SoBaseColor* pColor = new SoBaseColor;
	pColor->rgb.setValue( 1, 1, 1 );	

	mBBoxTransform = new SoMatrixTransform;
	mBBoxTransform->matrix.setValue( SbMatrix::identity() );

	SoBaseColor* secondColor = new SoBaseColor;
	secondColor->rgb.setValue( 0.5, 0.5, 0.5 );

	SoDrawStyle* secondStyle = new SoDrawStyle;
	secondStyle->pointSize.setValue(3);

	if( mControlPointsSwitch )
		mControlPointsSwitch->unref();

	SoSeparator* controlPointsSeparator = new SoSeparator;
	controlPointsSeparator->addChild( mBBoxTransform );
	controlPointsSeparator->addChild( mControlPointsCoords );
	controlPointsSeparator->addChild( mControlPointsStyle );
	controlPointsSeparator->addChild( pColor );
	controlPointsSeparator->addChild( new SoPointSet );
	controlPointsSeparator->addChild( mControlPointsCoords );
	controlPointsSeparator->addChild( secondStyle );
	controlPointsSeparator->addChild( secondColor );
	controlPointsSeparator->addChild( new SoPointSet );

	mControlPointsSwitch = new SoSwitch;
	mControlPointsSwitch->addChild( controlPointsSeparator );
	mControlPointsSwitch->ref();
}
コード例 #7
0
void SketcherValidation::showPoints(const std::vector<Base::Vector3d>& pts)
{
    SoCoordinate3 * coords = new SoCoordinate3();
    SoDrawStyle   * drawStyle = new SoDrawStyle();
    drawStyle->pointSize = 6;
    SoPointSet* pcPoints = new SoPointSet();

    coincidenceRoot = new SoGroup();

    coincidenceRoot->addChild(drawStyle);
    SoSeparator* pointsep = new SoSeparator();
    SoBaseColor * basecol = new SoBaseColor();
    basecol->rgb.setValue(1.0f, 0.5f, 0.0f);
    pointsep->addChild(basecol);
    pointsep->addChild(coords);
    pointsep->addChild(pcPoints);
    coincidenceRoot->addChild(pointsep);

    // Draw markers
    SoBaseColor * markcol = new SoBaseColor();
    markcol->rgb.setValue(1.0f, 1.0f, 0.0f);
    SoMarkerSet* marker = new SoMarkerSet();
    marker->markerIndex=SoMarkerSet::PLUS_9_9;
    pointsep->addChild(markcol);
    pointsep->addChild(marker);

    int pts_size = (int)pts.size();
    coords->point.setNum(pts_size);
    SbVec3f* c = coords->point.startEditing();
    for (int i = 0; i < pts_size; i++) {
        const Base::Vector3d& v = pts[i];
        c[i].setValue((float)v.x,(float)v.y,(float)v.z);
    }
    coords->point.finishEditing();

    Gui::ViewProvider* vp = Gui::Application::Instance->getViewProvider(sketch);
    vp->getRoot()->addChild(coincidenceRoot);
}
コード例 #8
0
ファイル: ViewProvider.cpp プロジェクト: mdjurfeldt/FreeCAD
SoPickedPoint* ViewProvider::getPointOnRay(const SbVec3f& pos,const SbVec3f& dir, const View3DInventorViewer* viewer) const
{
    // Note: There seems to be a  bug with setRay() which causes SoRayPickAction
    // to fail to get intersections between the ray and a line
    
    //first get the path to this node and calculate the current setTransformation
    SoSearchAction sa;
    sa.setNode(pcRoot);
    sa.setSearchingAll(true);
    sa.apply(viewer->getSoRenderManager()->getSceneGraph());
    SoGetMatrixAction gm(viewer->getSoRenderManager()->getViewportRegion());
    gm.apply(sa.getPath());
    
    // build a temporary scenegraph only keeping this viewproviders nodes and the accumulated 
    // transformation
    SoTransform* trans = new SoTransform;
    trans->ref();
    trans->setMatrix(gm.getMatrix());
    
    SoSeparator* root = new SoSeparator;
    root->ref();
    root->addChild(viewer->getSoRenderManager()->getCamera());
    root->addChild(trans);
    root->addChild(pcRoot);
    
    //get the picked point
    SoRayPickAction rp(viewer->getSoRenderManager()->getViewportRegion());
    rp.setRay(pos,dir);
    rp.setRadius(viewer->getPickRadius());
    rp.apply(root);
    root->unref();
    trans->unref();

    // returns a copy of the point
    SoPickedPoint* pick = rp.getPickedPoint();
    //return (pick ? pick->copy() : 0); // needs the same instance of CRT under MS Windows
    return (pick ? new SoPickedPoint(*pick) : 0);
}
コード例 #9
0
ファイル: AppSandboxGui.cpp プロジェクト: neuroidss/FreeCAD
    Py::Object interactiveFilletArc(const Py::Tuple& args)
    {
        Gui::Document* doc = Gui::Application::Instance->activeDocument();
        if (doc) {
            Gui::View3DInventor* view = qobject_cast<Gui::View3DInventor*>(doc->getActiveView());
            if (view) {
                Gui::View3DInventorViewer* viewer = view->getViewer();
                SoSeparator* scene = static_cast<SoSeparator*>(viewer->getSceneGraph());
                SoSeparator* node = new SoSeparator();
                SoBaseColor* rgb = new SoBaseColor();
                rgb->rgb.setValue(1,1,0);
                node->addChild(rgb);
                SoCoordinate3* coords = new SoCoordinate3();
                node->addChild(coords);
                node->addChild(new SoLineSet());
                scene->addChild(node);

                ObjectObserver* obs = new ObjectObserver(doc->getDocument()->getActiveObject(), coords);
                obs->attachDocument(doc->getDocument());
            }
        }
        return Py::None();
    }
コード例 #10
0
ファイル: AxisArrow.cpp プロジェクト: dewf/mrLab3d
static SoSeparator *arrowGeom(AxisArrow::AxisEnum axis, bool mirrored)
{
	SoSeparator *root = new SoSeparator();

    SoText2 *label = new SoText2();
    label->justification = SoText2::CENTER;
    if (axis == AxisArrow::AXIS_X) {
        label->string.setValue(mirrored ? "-X" : "+X");
    } else if (axis == AxisArrow::AXIS_Y) {
        label->string.setValue(mirrored ? "-Y" : "+Y");
    } else if (axis == AxisArrow::AXIS_Z) {
        label->string.setValue(mirrored ? "-Z" : "+Z");
    }

	float mul = mirrored ? -1.0f : 1.0f;

    // lines
    float verts[][3] = {
            // from origin to bottom of cone
            {0, mul * CONE_OFFS/4, 0},
            {0, mul * CONE_OFFS, 0},
    };
    SoCoordinate3 *coords = new SoCoordinate3();
    coords->point.setValues(0, 2, verts);
    root->addChild(coords);

    int indices[] = {
            0, 1, SO_END_LINE_INDEX,
    };
    SoIndexedLineSet *lines = new SoIndexedLineSet();
    lines->coordIndex.setValues(0, 3, indices);
    root->addChild(lines);

	if (mirrored) {
		// easiest way to mirror the cone, I guess
		SoRotationXYZ *rot = new SoRotationXYZ();
		rot->axis = SoRotationXYZ::X;
		rot->angle = M_PI;
		root->addChild(rot);
	}

    SoTranslation *xlat = new SoTranslation();
    xlat->translation.setValue(0, CONE_OFFS, 0);
    root->addChild(xlat);

    SoCone *cone = new SoCone();
    cone->bottomRadius = 0.35;
    cone->height = CONE_HEIGHT;
    root->addChild(cone);

    SoTranslation *xlat2 = new SoTranslation();
    xlat2->translation.setValue(0, CONE_HEIGHT/2+0.2, 0);
    root->addChild(xlat2);
    root->addChild(label);

	return root;
}
コード例 #11
0
void ViewProviderDatum::attach(App::DocumentObject *obj)
{
    ViewProviderGeometryObject::attach ( obj );

    // TODO remove this field (2015-09-08, Fat-Zer)
    App::DocumentObject* o = getObject();
    if (o->getTypeId() == PartDesign::Plane::getClassTypeId())
        datumType = QObject::tr("Plane");
    else if (o->getTypeId() == PartDesign::Line::getClassTypeId())
        datumType = QObject::tr("Line");
    else if (o->getTypeId() == PartDesign::Point::getClassTypeId())
        datumType = QObject::tr("Point");
    else if (o->getTypeId() == PartDesign::CoordinateSystem::getClassTypeId())
        datumType = QObject::tr("CoordinateSystem");

    SoShapeHints* hints = new SoShapeHints();
    hints->shapeType.setValue(SoShapeHints::UNKNOWN_SHAPE_TYPE);
    hints->vertexOrdering.setValue(SoShapeHints::COUNTERCLOCKWISE);
    SoDrawStyle* fstyle = new SoDrawStyle();
    fstyle->style = SoDrawStyle::FILLED;
    fstyle->lineWidth = 3;
    fstyle->pointSize = 5;
    pPickStyle->style = SoPickStyle::SHAPE;
    SoMaterialBinding* matBinding = new SoMaterialBinding;
    matBinding->value = SoMaterialBinding::OVERALL;

    SoSeparator* sep = new SoSeparator();
    sep->addChild(hints);
    sep->addChild(fstyle);
    sep->addChild(pPickStyle);
    sep->addChild(matBinding);
    sep->addChild(pcShapeMaterial);
    sep->addChild(pShapeSep);

    addDisplayMaskMode(sep, "Base");
}
コード例 #12
0
Standard_Boolean ViewProviderCurveNet::computeVertices(SoSeparator* root, const TopoDS_Shape &myShape)
{
    TopExp_Explorer ex;
    SoSeparator *VertexRoot = new SoSeparator();
    root->addChild(VertexRoot);

    VertexRoot->addChild(pcPointMaterial);

    SoComplexity *copl = new SoComplexity();
    copl->value = (float)0.2;
    VertexRoot->addChild(copl);

    for (ex.Init(myShape, TopAbs_VERTEX); ex.More(); ex.Next())
    {
        // get the shape 
        const TopoDS_Vertex& aVertex = TopoDS::Vertex(ex.Current());
        gp_Pnt gpPt = BRep_Tool::Pnt (aVertex);

        SoSeparator *TransRoot = new SoSeparator();
        SoTransform *Trans     = new SoTransform();
        TransRoot->addChild(Trans);
        Trans->translation.setValue((float)(gpPt.X()),(float)(gpPt.Y()),(float)(gpPt.Z()));

        SoLocateHighlight* h = new SoLocateHighlight();
        h->color.setValue((float)0.2,(float)0.5,(float)0.2);

        SoSphere * sphere = new SoSphere;
        sphere->radius = (float)pcPointStyle->pointSize.getValue();

        h->addChild(sphere);
        TransRoot->addChild(h);
        VertexRoot->addChild(TransRoot);
    }

    return true;
}
コード例 #13
0
bool SimoxRobotViewer::showPlane( const std::string &planeName, const Eigen::Vector3f &pos, const Eigen::Vector3f &n )
{
	removePlane(planeName);

	lock();
	SoSeparator* sep = new SoSeparator();
	sep->addChild(CoinVisualizationFactory::CreatePlaneVisualization(pos,n,4000.0f,0.5f));

	planes[planeName] = sep;

	// add visu
	sceneSep->addChild(sep);

	unlock();
	return true;
}
コード例 #14
0
bool SimoxRobotViewer::setEEFVisu( const std::string &eefVisuName, SoSeparator *vis )
{
    removeEEFVisu(eefVisuName);
    if (!vis)
        return false;
    lock();
    SoSeparator *v = new SoSeparator;
    SoMatrixTransform *mat = new SoMatrixTransform;
    mat->matrix.setValue(SbMatrix::identity());
    v->addChild(mat);
    v->addChild(vis);
    eefVisu[eefVisuName] = v;
    eefVisu[eefVisuName]->ref();
    unlock();
    showEEFVisu(eefVisuName,true);
    return true;
}
コード例 #15
0
ファイル: vpSimulator.cpp プロジェクト: tswang/visp
SoSeparator *
createCameraObject (const float zoomFactor = 1.0)
{
  vpDEBUG_TRACE (15, "# Entree.");

  SoSeparator * cam = new SoSeparator;
  cam->ref ();

  SoMaterial *myMaterial = new SoMaterial;
  myMaterial->diffuseColor.setValue(1.0, 0.0, 0.0);
  myMaterial->emissiveColor.setValue(0.5, 0.0, 0.0);

  SoScale *taille = new SoScale;
  {
    float zoom = 0.1f * zoomFactor;
    taille->scaleFactor.setValue (zoom, zoom, zoom);
  }

  SoMaterial *couleurBlanc = new SoMaterial;
  couleurBlanc->diffuseColor.setValue(1.0, 1.0, 1.0);
  couleurBlanc->emissiveColor.setValue(1.0, 1.0, 1.0);
  SoDrawStyle * filDeFer = new SoDrawStyle;
  filDeFer->style.setValue (SoDrawStyle::LINES);
  filDeFer->lineWidth.setValue (1);

  SoSeparator * cone = new SoSeparator;
  cone->ref();
  cone->addChild (makePyramide());
  cone->addChild (couleurBlanc);
  cone->addChild (filDeFer);
  cone->addChild (makePyramide());
  cone->unrefNoDelete();

  cam->addChild(myMaterial);
  cam->addChild(taille);
  cam->addChild(cone);
  cam->addChild(createFrame(2.0f,0.1f,0.01f));

  //  cam->unref() ;
  vpDEBUG_TRACE (15, "# Sortie.");
  return cam;
}
コード例 #16
0
SoFCBoundingBox::SoFCBoundingBox ()
{
    SO_NODE_CONSTRUCTOR(SoFCBoundingBox);

    SO_NODE_ADD_FIELD(minBounds, (-1.0, -1.0, -1.0));
    SO_NODE_ADD_FIELD(maxBounds, ( 1.0,  1.0,  1.0));
    SO_NODE_ADD_FIELD(coordsOn, (true));
    SO_NODE_ADD_FIELD(dimensionsOn, (true));

    root = new SoSeparator();
    SoSeparator *bboxSep = new SoSeparator();

    bboxCoords = new SoCoordinate3();
    bboxCoords->point.setNum(8);
    bboxSep->addChild(bboxCoords);
    root->addChild(bboxSep);

    // the lines of the box
    bboxLines  = new SoIndexedLineSet();
    bboxLines->coordIndex.setNum(36);
    bboxLines->coordIndex.setValues(0, 36, bBoxEdges);
    bboxSep->addChild(bboxLines);
  

    // create the text nodes, including a transform for each vertice offset
    textSep = new SoSeparator();
    for (int i = 0; i < 8; i++) {
        SoSeparator *temp = new SoSeparator();
        SoTransform *trans = new SoTransform();
        temp->addChild(trans);
        SoText2* text = new SoText2();
        text->justification.setValue(SoText2::CENTER);
        temp->addChild(text);
        textSep->addChild(temp);
    }

    // create the text nodes, including a transform for each dimension
    dimSep = new SoSeparator();
    for (int i = 0; i < 3; i++) {
        SoSeparator *temp = new SoSeparator();
        SoTransform *trans = new SoTransform();
        temp->addChild(trans);
        SoText2* text = new SoText2();
        text->justification.setValue(SoText2::CENTER);
        temp->addChild(text);
        dimSep->addChild(temp);
    }

    root->addChild(textSep);
    root->addChild(dimSep);
    root->ref();
}
コード例 #17
0
ファイル: superimposition.cpp プロジェクト: alamador91/test
static SoSeparator * create_background(void)
{
  // create a gradient background
  SoSeparator * root = new SoSeparator;
  SoBaseColor * color = new SoBaseColor;
  SoOrthographicCamera * orthocam = new SoOrthographicCamera;

  color->rgb.set1Value(0, SbColor(1.0, 0.0, 0.0));
  color->rgb.set1Value(1, SbColor(1.0, 1.0, 0.0));

  orthocam->height.setValue(1.0);
  orthocam->viewportMapping = SoCamera::LEAVE_ALONE;
  orthocam->nearDistance.setValue(0.0);
  orthocam->farDistance.setValue(2.0);
  orthocam->position = SbVec3f(0.0f, 0.0f, 1.0f);

  SoMaterialBinding * mb = new SoMaterialBinding;
  mb->value = SoMaterialBinding::PER_VERTEX_INDEXED;

  SoCoordinate3 * coords = new SoCoordinate3;
  coords->point.set1Value(0, SbVec3f(-0.5f, -0.5f, 0.0f));
  coords->point.set1Value(1, SbVec3f(0.5f, -0.5f, 0.0f));
  coords->point.set1Value(2, SbVec3f(0.5f, 0.5f, 0.0f));
  coords->point.set1Value(3, SbVec3f(-0.5f, 0.5f, 0.0f));

  SoIndexedFaceSet * ifs = new SoIndexedFaceSet;
  ifs->coordIndex.set1Value(0, 0);
  ifs->coordIndex.set1Value(1, 1);
  ifs->coordIndex.set1Value(2, 2);
  ifs->coordIndex.set1Value(3, 3);
  ifs->coordIndex.set1Value(4, -1);

  ifs->materialIndex.set1Value(0, 0);
  ifs->materialIndex.set1Value(1, 0);
  ifs->materialIndex.set1Value(2, 1);
  ifs->materialIndex.set1Value(3, 1);
  ifs->materialIndex.set1Value(4, -1);

  SoLightModel * lm = new SoLightModel;
  lm->model = SoLightModel::BASE_COLOR;

  root->addChild(orthocam);
  root->addChild(lm);
  root->addChild(color);
  root->addChild(mb);
  root->addChild(coords);
  root->addChild(ifs);

  return root;

}
コード例 #18
0
bool SimoxRobotViewer::showPath( const std::string &pathName, VirtualRobot::TrajectoryPtr path, VirtualRobot::VisualizationFactory::Color c )
{
	removePath(pathName);
	if (!path)
		return false;
	lock();
	VirtualRobot::RobotNodeSetPtr rns = path->getRobotNodeSet();
	if (!rns)
	{
		VR_ERROR << "No rns" << endl;
        unlock();
		return false;
	}
	RobotNodePtr tcp = rns->getTCP();
	if (!tcp)
	{
		VR_ERROR << "No tcp" << endl;
		unlock();
		return false;
	}
	SoSeparator *sep = new SoSeparator;
	sep->addChild(VirtualRobot::CoinVisualizationFactory::getCoinVisualization(path));
	//Saba::CoinRrtWorkspaceVisualization cv(robot,cspace,tcp->getName());
	//cv.setCustomColor(c.r,c.g,c.b);
	//cv.addCSpacePath(path,Saba::CoinRrtWorkspaceVisualization::eCustom);
	//SoSeparator *sep = cv.getCoinVisualization();
	if (!sep)
	{
		unlock();
		return false;
	}
	pathData pd;
	pd.trajectory = path;
	pd.visu = sep;
	paths[pathName] = pd;

	// add visu
	sceneSep->addChild(sep);
	unlock();
	return true;
}
コード例 #19
0
void ViewProviderMeasureDistance::attach(App::DocumentObject* pcObject)
{
    ViewProviderDocumentObject::attach(pcObject);

    SoPickStyle* ps = new SoPickStyle();
    ps->style = SoPickStyle::UNPICKABLE;

    SoSeparator *lineSep = new SoSeparator();
    SoDrawStyle* style = new SoDrawStyle();
    style->lineWidth = 2.0f;
    lineSep->addChild(ps);
    lineSep->addChild(style);
    lineSep->addChild(pColor);
    lineSep->addChild(pCoords);
    lineSep->addChild(pLines);
    SoMarkerSet* points = new SoMarkerSet();
    points->markerIndex = SoMarkerSet::CROSS_9_9;
    points->numPoints=2;
    lineSep->addChild(points);

    // Making the whole measurement object selectable by 3d view can
    // become cumbersome since it has influence to any raypick action.
    // Thus, it's only selectable by its text label
    SoFCSelection* textsep = new SoFCSelection();
    textsep->objectName = pcObject->getNameInDocument();
    textsep->documentName = pcObject->getDocument()->getName();
    textsep->subElementName = "Main";
    //SoSeparator* textsep = new SoSeparator();
    textsep->addChild(pTranslation);
    textsep->addChild(pTextColor);
    textsep->addChild(pFont);
    textsep->addChild(pLabel);

    SoSeparator* sep = new SoSeparator();
    sep->addChild(lineSep);
    sep->addChild(textsep);
    addDisplayMaskMode(sep, "Base");
}
コード例 #20
0
ファイル: ivselector.cpp プロジェクト: AbuShaqra/openrave
SoSeparator* IvDragger::_CreateAxes(float fSize,float fColor)
{
    SoSeparator* axes = new SoSeparator();
    Vector colors[] = { Vector(0,0,fColor),Vector(0,fColor,0),Vector(fColor,0,0)};
    Vector rotations[] = { Vector(1,0,0,PI/2), Vector(1,0,0,0), Vector(0,0,1,-PI/2)};

    // add 3 cylinder+cone axes
    for(int i = 0; i < 3; ++i) {
        // set a diffuse color
        SoSeparator* psep = new SoSeparator();

        SoMaterial* mtrl = new SoMaterial;
        mtrl->diffuseColor = SbColor(colors[i].x, colors[i].y, colors[i].z);
        mtrl->ambientColor = SbColor(colors[i].x, colors[i].y, colors[i].z);
        mtrl->setOverride(true);

        SoTransform* protation = new SoTransform();
        protation->rotation.setValue(SbVec3f(rotations[i].x, rotations[i].y, rotations[i].z), rotations[i].w);

        SoTransform* pcyltrans = new SoTransform();
        pcyltrans->translation.setValue(0,0.02f*fSize,0);

        SoCylinder* c = new SoCylinder();
        c->radius = 0.002f*fSize;
        c->height = 0.04f*fSize;

        SoCone* cn = new SoCone();
        cn->bottomRadius = 0.004f*fSize;
        cn->height = 0.02f*fSize;

        SoTransform* pconetrans = new SoTransform();
        pconetrans->translation.setValue(0,0.02f*fSize,0);

        psep->addChild(mtrl);
        psep->addChild(protation);
        psep->addChild(pcyltrans);
        psep->addChild(c);
        psep->addChild(pconetrans);
        psep->addChild(cn);
        axes->addChild(psep);
    }
    return axes;
}
コード例 #21
0
int main(int, char ** argv)
{
	
	HWND window = SoWin::init("Oil Well");
	if (window == NULL) exit(1);
	SoWinExaminerViewer * viewer = new SoWinExaminerViewer(window);
	viewer->setDecoration(false);
	viewer->setSize(SbVec2s(800, 600));
	SoSeparator *root = new SoSeparator;
	root->ref();
	SoSeparator *obelisk = new SoSeparator();

	// Define the normals used:
	SoNormal *myNormals = new SoNormal;
	myNormals->vector.setValues(0, 8, norms);
	obelisk->addChild(myNormals);
	SoNormalBinding *myNormalBinding = new SoNormalBinding;
	myNormalBinding->value = SoNormalBinding::PER_FACE;
	obelisk->addChild(myNormalBinding);
	// Define material for obelisk
	SoMaterial *myMaterial = new SoMaterial;
	myMaterial->diffuseColor.setValue(.4, .4, .4);
	obelisk->addChild(myMaterial);
	// Define coordinates for vertices
	SoCoordinate3 *myCoords = new SoCoordinate3;
	myCoords->point.setValues(0, 28, vertices);
	obelisk->addChild(myCoords);
	// Define the FaceSet
	SoFaceSet *myFaceSet = new SoFaceSet;
	myFaceSet->numVertices.setValues(0, 8, numvertices);
	obelisk->addChild(myFaceSet);

	root->addChild(obelisk);

	viewer->setSceneGraph(root);
	viewer->setTitle("Oil Well");
	viewer->show();
	SoWin::show(window);
	SoWin::mainLoop();
	delete viewer;
	root->unref();
	return 0;
}
コード例 #22
0
ファイル: glut_tex.cpp プロジェクト: Alexpux/Coin3D
SoSeparator *
createScenegraph(void)
{
  SoSeparator * texroot = new SoSeparator;
  texroot->ref();
  SoInput in;
  in.setBuffer(red_cone_iv, strlen(red_cone_iv));
  
  SoSeparator * result = SoDB::readAll(&in);
  if (result == NULL) { exit(1); }
 
  SoPerspectiveCamera *myCamera = new SoPerspectiveCamera;
  SoRotationXYZ *rot = new SoRotationXYZ;
  rot->axis  = SoRotationXYZ::X;
  rot->angle = M_PI_2;
  myCamera->position.setValue(SbVec3f(-0.2, -0.2, 2.0));
  myCamera->scaleHeight(0.4);
  texroot->addChild(myCamera);
  texroot->addChild(new SoDirectionalLight);
  texroot->addChild(rot);
  texroot->addChild(result);
  myCamera->viewAll(texroot, SbViewportRegion());

  // Generate the texture map
  SoTexture2 *texture = new SoTexture2;
  texture->ref();
  if (generateTextureMap(texroot, texture, 128, 128))
    printf ("Successfully generated texture map\n");
  else
    printf ("Could not generate texture map\n");
  texroot->unref();

  // Make a scene with a cube and apply the texture to it
  SoSeparator * root = new SoSeparator;
  root->addChild(texture);
  root->addChild(new SoCube);
  return root;
}
コード例 #23
0
void ViewProviderOriginFeature::attach(App::DocumentObject* pcObject)
{
    ViewProviderGeometryObject::attach(pcObject);

    float defaultSz = ViewProviderOrigin::defaultSize();
    float sz = Size.getValue () / defaultSz;

    // Create an external separator
    SoSeparator  *sep = new SoSeparator();

    // Add material from the base class
    sep->addChild(pcShapeMaterial);

    // Bind same material to all part
    SoMaterialBinding* matBinding = new SoMaterialBinding;
    matBinding->value = SoMaterialBinding::OVERALL;
    sep->addChild(matBinding);

    // Scale feature to the given size
    pScale->scaleFactor = SbVec3f (sz, sz, sz);
    sep->addChild (pScale);

    // Setup font size
    SoFont *font = new SoFont ();
    font->size.setValue ( defaultSz/10.);
    sep->addChild ( font );

    // Create the selection node
    SoFCSelection *highlight = new SoFCSelection ();
    highlight->applySettings ();
    if ( !Selectable.getValue() ) {
        highlight->selectionMode = Gui::SoFCSelection::SEL_OFF;
    }
    highlight->objectName    = getObject()->getNameInDocument();
    highlight->documentName  = getObject()->getDocument()->getName();
    highlight->style = SoFCSelection::EMISSIVE_DIFFUSE;

    // Style for normal (visiable) lines
    SoDrawStyle* style = new SoDrawStyle ();
    style->lineWidth = 2.0f;
    highlight->addChild ( style );

    // Visible lines
    highlight->addChild ( pOriginFeatureRoot );

    // Hidden features
    SoAnnotation *hidden = new SoAnnotation ();

    // Style for hidden lines
    style = new SoDrawStyle ();
    style->lineWidth = 2.0f;
    style->linePattern.setValue ( 0xF000 ); // (dash-skip-skip-skip)
    hidden->addChild ( style );

    // Hidden lines
    hidden->addChild ( pOriginFeatureRoot );

    highlight->addChild ( hidden );

    sep->addChild ( highlight );

    // Setup the object label as it's text
    pLabel->string.setValue ( SbString ( pcObject->Label.getValue () ) );

    addDisplayMaskMode ( sep, "Base" );
}
コード例 #24
0
void ViewProviderSpline::showControlPointsOfFace(const TopoDS_Face& face)
{
    std::list<gp_Pnt> knots;
    std::vector<std::vector<gp_Pnt> > poles;
    Standard_Integer nCtU=0, nCtV=0;
    BRepAdaptor_Surface surface(face);

    BRepAdaptor_Surface clSurface(face);
    switch (clSurface.GetType())
    {
    case GeomAbs_BezierSurface:
        {
            Handle(Geom_BezierSurface) hBezier = surface.Bezier();
            nCtU = hBezier->NbUPoles();
            nCtV = hBezier->NbVPoles();
            poles.resize(nCtU);
            for (Standard_Integer u = 1; u <= nCtU; u++) {
                poles[u-1].resize(nCtV);
                for (Standard_Integer v = 1; v <= nCtV; v++)
                    poles[u-1][v-1] = hBezier->Pole(u, v);
            }
        }   break;
    case GeomAbs_BSplineSurface:
        {
            Handle(Geom_BSplineSurface) hBSpline = surface.BSpline();
            nCtU = hBSpline->NbUPoles();
            nCtV = hBSpline->NbVPoles();
            poles.resize(nCtU);
            for (Standard_Integer u = 1; u <= nCtU; u++) {
                poles[u-1].resize(nCtV);
                for (Standard_Integer v = 1; v <= nCtV; v++)
                    poles[u-1][v-1] = hBSpline->Pole(u, v);
            }

            //Standard_Integer nKnU = hBSpline->NbUKnots();
            //Standard_Integer nKnV = hBSpline->NbVKnots();
            for (Standard_Integer u = 1; u <= hBSpline->NbUKnots(); u++) {
                for (Standard_Integer v = 1; v <= hBSpline->NbVKnots(); v++)
                    knots.push_back(hBSpline->Value(hBSpline->UKnot(u), hBSpline->VKnot(v)));
            }
        }   break;
    default:
        break;
    }

    if (poles.empty())
        return; // nothing to do

    SoCoordinate3 * coords = new SoCoordinate3;
    coords->point.setNum(nCtU * nCtV + knots.size());

    int index=0;
    SbVec3f* verts = coords->point.startEditing();
    for (std::vector<std::vector<gp_Pnt> >::iterator u = poles.begin(); u != poles.end(); ++u) {
        for (std::vector<gp_Pnt>::iterator v = u->begin(); v != u->end(); ++v) {
            verts[index++].setValue((float)v->X(), (float)v->Y(), (float)v->Z());
        }
    }
    for (std::list<gp_Pnt>::iterator k = knots.begin(); k != knots.end(); ++k) {
        verts[index++].setValue((float)k->X(), (float)k->Y(), (float)k->Z());
    }
    coords->point.finishEditing();


    SoFCControlPoints* control = new SoFCControlPoints();
    control->numPolesU = nCtU;
    control->numPolesV = nCtV;

    //if (knots.size() > 0) {
    //    control->numKnotsU = nKnU;
    //    control->numKnotsV = nKnV;
    //}

    SoSeparator* nodes = new SoSeparator();
    nodes->addChild(coords);
    nodes->addChild(control);

    pcControlPoints->addChild(nodes);
}
コード例 #25
0
void ViewProviderSpline::showControlPointsOfEdge(const TopoDS_Edge& edge)
{
    std::list<gp_Pnt> poles, knots;
    Standard_Integer nCt=0;
    BRepAdaptor_Curve curve(edge);
    switch (curve.GetType())
    {
    case GeomAbs_BezierCurve:
        {
            Handle(Geom_BezierCurve) hBezier = curve.Bezier();
            nCt = hBezier->NbPoles();
            for (Standard_Integer i = 1; i <= nCt; i++)
                poles.push_back(hBezier->Pole(i));
            if (hBezier->IsClosed()) {
                nCt++;
                poles.push_back(hBezier->Pole(1));
            }
        }   break;
    case GeomAbs_BSplineCurve:
        {
            Handle(Geom_BSplineCurve) hBSpline = curve.BSpline();
            nCt = hBSpline->NbPoles();
            for (Standard_Integer i = 1; i <= nCt; i++)
                poles.push_back(hBSpline->Pole(i));
            if (hBSpline->IsClosed()) {
                nCt++;
                poles.push_back(hBSpline->Pole(1));
            }
            for (Standard_Integer i = hBSpline->FirstUKnotIndex()+1; i <= hBSpline->LastUKnotIndex()-1; i++)
                knots.push_back(hBSpline->Value(hBSpline->Knot(i)));
        }   break;
    default:
        break;
    }

    if (poles.empty())
        return; // nothing to do

    SoCoordinate3 * controlcoords = new SoCoordinate3;
    controlcoords->point.setNum(nCt + knots.size());

    int index=0;
    SbVec3f* verts = controlcoords->point.startEditing();
    for (std::list<gp_Pnt>::iterator p = poles.begin(); p != poles.end(); ++p) {
        verts[index++].setValue((float)p->X(), (float)p->Y(), (float)p->Z());
    }
    for (std::list<gp_Pnt>::iterator k = knots.begin(); k != knots.end(); ++k) {
        verts[index++].setValue((float)k->X(), (float)k->Y(), (float)k->Z());
    }
    controlcoords->point.finishEditing();


    SoFCControlPoints* controlpoints = new SoFCControlPoints();
    controlpoints->numPolesU = nCt;
    controlpoints->numPolesV = 1;

    SoSeparator* nodes = new SoSeparator();
    nodes->addChild(controlcoords);
    nodes->addChild(controlpoints);

    pcControlPoints->addChild(nodes);
}
コード例 #26
0
ファイル: ivworkspace.cpp プロジェクト: joseparnau/rosjac
	SoSeparator* IVWorkSpace::calculateBoundingBox(SoSeparator *element){
		// set up an engine to calculate the bounding box of the element parameter
		SoComputeBoundingBox * bboxEngine = new SoComputeBoundingBox;
		bboxEngine->node = element;

		// decompose the vectors into separate floating point values
		SoDecomposeVec3f * dep1 = new SoDecomposeVec3f;
		SoDecomposeVec3f * dep2 = new SoDecomposeVec3f;
		dep1->vector.connectFrom(&bboxEngine->min);
		dep2->vector.connectFrom(&bboxEngine->max);

		// create engines to compose vectors again. We need eight vectors,
		// one for each vertex in the bounding box.
		SoComposeVec3f * comp1 = new SoComposeVec3f;
		SoComposeVec3f * comp2 = new SoComposeVec3f;
		SoComposeVec3f * comp3 = new SoComposeVec3f;
		SoComposeVec3f * comp4 = new SoComposeVec3f;
		SoComposeVec3f * comp5 = new SoComposeVec3f;
		SoComposeVec3f * comp6 = new SoComposeVec3f;
		SoComposeVec3f * comp7 = new SoComposeVec3f;
		SoComposeVec3f * comp8 = new SoComposeVec3f;

		// connect the engines so that all corner points are covered
		comp1->x.connectFrom(&dep1->x);
		comp1->y.connectFrom(&dep1->y);
		comp1->z.connectFrom(&dep1->z);

		comp2->x.connectFrom(&dep2->x);
		comp2->y.connectFrom(&dep1->y);
		comp2->z.connectFrom(&dep1->z);

		comp3->x.connectFrom(&dep2->x);
		comp3->y.connectFrom(&dep2->y);
		comp3->z.connectFrom(&dep1->z);

		comp4->x.connectFrom(&dep1->x);
		comp4->y.connectFrom(&dep2->y);
		comp4->z.connectFrom(&dep1->z);

		comp5->x.connectFrom(&dep1->x);
		comp5->y.connectFrom(&dep1->y);
		comp5->z.connectFrom(&dep2->z);

		comp6->x.connectFrom(&dep2->x);
		comp6->y.connectFrom(&dep1->y);
		comp6->z.connectFrom(&dep2->z);

		comp7->x.connectFrom(&dep2->x);
		comp7->y.connectFrom(&dep2->y);
		comp7->z.connectFrom(&dep2->z);

		comp8->x.connectFrom(&dep1->x);
		comp8->y.connectFrom(&dep2->y);
		comp8->z.connectFrom(&dep2->z);

		// concatenate the eight vectors into a single SoMFVec3f field
		SoConcatenate * con = new SoConcatenate(SoMFVec3f::getClassTypeId());
		con->input[0]->connectFrom(&comp1->vector);
		con->input[1]->connectFrom(&comp2->vector);
		con->input[2]->connectFrom(&comp3->vector);
		con->input[3]->connectFrom(&comp4->vector);
		con->input[4]->connectFrom(&comp5->vector);
		con->input[5]->connectFrom(&comp6->vector);
		con->input[6]->connectFrom(&comp7->vector);
		con->input[7]->connectFrom(&comp8->vector);

		// construct a new scene graph, that includes an indexed line to
		// render the bounding box.

		SoSeparator* sep = new SoSeparator;

		SoLightModel* lm = new SoLightModel;
		lm->model = SoLightModel::BASE_COLOR;
		SoCoordinate3* coords = new SoCoordinate3;

		// use the points calculated by our engines
		coords->point.connectFrom(con->output);

		SoDrawStyle* ds = new SoDrawStyle;
		ds->lineWidth = 2;
		ds->linePattern = 0xf0f0;

		SoIndexedLineSet* ls = new SoIndexedLineSet;
		const int32_t idx[] = {0,1,2,3,0,-1,4,5,6,7,4,-1,
													 1,5,-1,2,6,-1,3,7,-1,0,4,-1};
		ls->coordIndex.setNum(24);
		ls->coordIndex.setValues(0, 24, idx);

		sep->addChild(lm);
		sep->addChild(coords);
		sep->addChild(ds);
		sep->addChild(ls);
		sep->ref();
		return sep;
	}
コード例 #27
0
ファイル: handViewWindow.cpp プロジェクト: CURG/graspit_bci
//HandViewWindow:
//Set the HandViewWindow which contains he views themselves
HandViewWindow::HandViewWindow(QWidget * parent, Hand * h, const QRect & geom, SoNode * IVRoot, QWidget * stageFrame):currentPreviewIndex(-1),
maxViewSize(3), cloneHand(new Hand(h->getWorld(), "newHand")), geom_(geom), grid(NULL), stageFrame_(stageFrame)
{


  handViewWindow = new QFrame(NULL);
  handViewWindow->setWindowFlags(Qt::WindowStaysOnTopHint);
  viewHolder = new QFrame(NULL);
  handViewWindow->setGeometry(geom);
  hbox = new QHBoxLayout(handViewWindow);

    handViewWindow->show();
    viewHolder->setGeometry(0,0,2*geom_.width()/3,2*geom_.height()/3);
  viewHolder->setMinimumSize(2*geom_.width()/3,2*geom_.height()/3);
  viewHolder->setMaximumSize(2*geom_.width()/3,2*geom_.height()/3);
  viewHolder->setFrameStyle(QFrame::Box | QFrame::Raised);
 viewHolder->setLineWidth(2);
  if(IVRoot)
    {
      SoQtRenderArea * render = new SoQtRenderArea(viewHolder, " ",true);

      vbox1 = new QVBoxLayout();
      hbox->addLayout(vbox1);
      vbox1->addWidget(viewHolder);
      vbox1->addWidget(stageFrame);
      //render->setSceneGraph(IVRoot);
      SoSeparator * testRoot = new SoSeparator;
      //SoCone * testCone = new SoCone;
      //SoCamera * testCamera = new SoPerspectiveCamera;

      SoMaterial * testMaterial = new SoMaterial;

      testMaterial->diffuseColor.setValue(1,0,0);
      testRoot->addChild(graspItGUI->getIVmgr()->getViewer()->getCamera());
      SoTransformSeparator *lightSep = new SoTransformSeparator;
      SoRotation *lightDir = new SoRotation;
      lightDir->rotation.connectFrom(&graspItGUI->getIVmgr()->getViewer()->getCamera()->orientation);
      lightSep->addChild(lightDir);
      lightSep->addChild(graspItGUI->getIVmgr()->getViewer()->getHeadlight());
      SoLightModel * model = new SoLightModel;
      model->model=SoLightModel::PHONG;
      testRoot->addChild(lightSep);
      testRoot->addChild(model);
      testRoot->addChild(IVRoot);
      render->setSceneGraph(testRoot);
      render->setBackgroundColor(SbColor(1,1,1));
      render->scheduleRedraw();
      render->render();
      render->show();
    }
    vbox2 = new QVBoxLayout();
  vbox2->setGeometry(QRect(0,0,geom_.width()/3,geom_.height()));
  vbox2->setSizeConstraint(QLayout::SetMinimumSize);
  hbox->addLayout(vbox2);

 // vbox2->addWidget(new QWidget());
  //handViewWindow->setWindowFlags(Qt::WindowStaysOnTopHint);
  //handViewWindow->resize(QSize(900,100));
   //handViewFrame->setGeometry(geom_);
   handViewWindow->setFrameStyle(QFrame::Box | QFrame::Raised);
   handViewWindow->setLineWidth(4);


  cloneHand->cloneFrom(h);
  cloneHand->setTransparency(0.0);
  cloneHand->setRenderGeometry(false);
  cloneHand->showVirtualContacts(false);
  cloneHand->getWorld()->toggleCollisions(false, cloneHand);
}
コード例 #28
0
ファイル: RRTdemo.cpp プロジェクト: gkalogiannis/simox
void startRRTVisualization()
{

    // create robot
    std::string filename("robots/examples/RrtDemo/Joint3.xml");
    VirtualRobot::RuntimeEnvironment::getDataFileAbsolute(filename);
    cout << "Loading 3DOF robot from " << filename << endl;
    RobotPtr robot = RobotIO::loadRobot(filename);

    if (!robot)
    {
        return;
    }


    float sampling_extend_stepsize = 0.04f;

    // create environment
    float posX = 0.0f, posY = -400.0f, posZ = 400.0f, sizeX = 100.0f, sizeY = 300.0f, sizeZ = 1000.0f;
    ObstaclePtr o = Obstacle::createBox(sizeX, sizeY, sizeZ);

    Eigen::Affine3f tmpT(Eigen::Translation3f(posX, posY, posZ));
    o->setGlobalPose(tmpT.matrix());


    // setup collision detection
    std::string colModelName("CollisionModel");
    SceneObjectSetPtr cms = robot->getRobotNodeSet(colModelName);
    CDManagerPtr cdm(new CDManager());
    cdm->addCollisionModel(cms);
    cdm->addCollisionModel(o);

    float planningTime = 0;
    int failed = 0;
    int loops = 1;
    bool ok;
    CSpaceSampledPtr cspace;
    std::string planningJoints("AllJoints");
    RobotNodeSetPtr planningNodes = robot->getRobotNodeSet(planningJoints);
#ifdef USE_BIRRT
    BiRrtPtr rrt;
#else
    RrtPtr rrt;
#endif
    Eigen::VectorXf start(3);
    start(0) = (float)M_PI / 4.0f;
    start(1) = (float)M_PI / 4.0f * 1.5f;
    start(2) = (float) - M_PI / 4.0f;

    Eigen::VectorXf goal(3);
    goal(0) = (float) - M_PI / 4.0f;
    goal(1) = (float)M_PI / 4.0f * 1.5f;
    goal(2) = (float) - M_PI / 4.0f;

    for (int i = 0; i < loops; i++)
    {
        // setup C-Space

        cspace.reset(new CSpaceSampled(robot, cdm, planningNodes));
        cspace->setSamplingSize(sampling_extend_stepsize);
        cspace->setSamplingSizeDCD(sampling_extend_stepsize);
        // setup planner


#ifdef USE_BIRRT
        rrt.reset(new BiRrt(cspace));
#else
        rrt.reset(new Rrt(cspace));
#endif
        rrt->setStart(start);
        rrt->setGoal(goal);

        clock_t startT = clock();
        ok = rrt->plan(true);
        clock_t endT = clock();

        float diffClock = (float)(((float)(endT - startT) / (float)CLOCKS_PER_SEC) * 1000.0f);
        planningTime += diffClock;

        if (!ok)
        {
            failed++;
        }
    }

    planningTime /= (float)loops;
    cout << "Avg planning time: " << planningTime << endl;
    cout << "failed:" << failed << endl;

    if (!ok)
    {
        cout << "planning failed..." << endl;
        return;
    }

    CSpacePathPtr solution = rrt->getSolution();
    CSpaceTreePtr tree = rrt->getTree();



    robot->setJointValues(planningNodes, start);

    // display robot
    SoSeparator* sep = new SoSeparator();
    SceneObject::VisualizationType colModel = SceneObject::Full;

    boost::shared_ptr<CoinVisualization> visualization = robot->getVisualization<CoinVisualization>(colModel);
    SoNode* visualisationNode = NULL;

    if (visualization)
    {
        visualisationNode = visualization->getCoinVisualization();
    }

    sep->addChild(visualisationNode);

    // display obstacle
    VisualizationNodePtr visuObstacle = o->getVisualization();
    std::vector<VisualizationNodePtr> visus;
    visus.push_back(visuObstacle);
    boost::shared_ptr<CoinVisualization> visualizationO(new CoinVisualization(visus));
    SoNode* obstacleSoNode = visualizationO->getCoinVisualization();
    sep->addChild(obstacleSoNode);

    // show rrt visu
    boost::shared_ptr<CoinRrtWorkspaceVisualization> w(new CoinRrtWorkspaceVisualization(robot, cspace, "EndPoint"));
    w->addTree(tree);
#ifdef USE_BIRRT
    CSpaceTreePtr tree2 = rrt->getTree2();
    w->addTree(tree2);
#endif
    w->addCSpacePath(solution);
    w->addConfiguration(start, CoinRrtWorkspaceVisualization::eGreen, 3.0f);
    w->addConfiguration(goal, CoinRrtWorkspaceVisualization::eGreen, 3.0f);
    SoSeparator* sol = w->getCoinVisualization();
    sep->addChild(sol);

    show(sep);
}
コード例 #29
0
void ViewProviderFemConstraintPulley::updateData(const App::Property* prop)
{
    // Gets called whenever a property of the attached object changes
    Fem::ConstraintPulley* pcConstraint = static_cast<Fem::ConstraintPulley*>(this->getObject());

    if (strcmp(prop->getName(),"BasePoint") == 0) {
        if (pcConstraint->Height.getValue() > Precision::Confusion()) {
            // Remove and recreate the symbol
            pShapeSep->removeAllChildren();

            // This should always point outside of the cylinder
            Base::Vector3d base = pcConstraint->BasePoint.getValue();
            Base::Vector3d axis = pcConstraint->Axis.getValue();
            double radius = pcConstraint->Radius.getValue();
            double dia = pcConstraint->Diameter.getValue();
            if (dia < 2 * radius)
                dia = 2 * radius;
            double forceAngle = pcConstraint->ForceAngle.getValue() / 180 * M_PI;
            double beltAngle = pcConstraint->BeltAngle.getValue();
            double rat1 = 0.8, rat2 = 0.2;
            double f1 = pcConstraint->BeltForce1.getValue();
            double f2 = pcConstraint->BeltForce2.getValue();
            if (f1+f2 > Precision::Confusion()) {
                rat1 = f1 / (f1+f2);
                rat2 = f2 / (f1+f2);
            }

            SbVec3f b(base.x, base.y, base.z);
            SbVec3f ax(axis.x, axis.y, axis.z);

            createPlacement(pShapeSep, b, SbRotation(SbVec3f(0,1,0), ax)); // child 0 and 1
            pShapeSep->addChild(createCylinder(pcConstraint->Height.getValue() * 0.8, dia/2)); // child 2
            SoSeparator* sep = new SoSeparator();
            createPlacement(sep, SbVec3f(dia/2 * sin(forceAngle+beltAngle), 0, dia/2 * cos(forceAngle+beltAngle)),
                SbRotation(SbVec3f(0,1,0), SbVec3f(sin(forceAngle+beltAngle+M_PI_2),0,cos(forceAngle+beltAngle+M_PI_2))));
            createPlacement(sep, SbVec3f(0, dia/8 + dia/2 * rat1, 0), SbRotation());
            sep->addChild(createArrow(dia/8 + dia/2 * rat1, dia/8));
            pShapeSep->addChild(sep); // child 3
            sep = new SoSeparator();
            createPlacement(sep, SbVec3f(-dia/2 * sin(forceAngle-beltAngle), 0, -dia/2 * cos(forceAngle-beltAngle)),
                SbRotation(SbVec3f(0,1,0), SbVec3f(-sin(forceAngle-beltAngle-M_PI_2),0,-cos(forceAngle-beltAngle-M_PI_2))));
            createPlacement(sep, SbVec3f(0, dia/8 + dia/2 * rat2, 0), SbRotation());
            sep->addChild(createArrow(dia/8 + dia/2 * rat2, dia/8));
            pShapeSep->addChild(sep); // child 4
        }
    } else if (strcmp(prop->getName(),"Diameter") == 0) {
        if (pShapeSep->getNumChildren() > 0) {
            // Change the symbol
            double radius = pcConstraint->Radius.getValue();
            double dia = pcConstraint->Diameter.getValue();
            if (dia < 2 * radius)
                dia = 2 * radius;
            double forceAngle = pcConstraint->ForceAngle.getValue() / 180 * M_PI;
            double beltAngle = pcConstraint->BeltAngle.getValue();
            double rat1 = 0.8, rat2 = 0.2;
            double f1 = pcConstraint->BeltForce1.getValue();
            double f2 = pcConstraint->BeltForce2.getValue();
            if (f1+f2 > Precision::Confusion()) {
                rat1 = f1 / (f1+f2);
                rat2 = f2 / (f1+f2);
            }

            const SoSeparator* sep = static_cast<SoSeparator*>(pShapeSep->getChild(2));
            updateCylinder(sep, 0, pcConstraint->Height.getValue() * 0.8, dia/2);
            sep = static_cast<SoSeparator*>(pShapeSep->getChild(3));
            updatePlacement(sep, 0, SbVec3f(dia/2 * sin(forceAngle+beltAngle), 0, dia/2 * cos(forceAngle+beltAngle)),
                SbRotation(SbVec3f(0,1,0), SbVec3f(sin(forceAngle+beltAngle+M_PI_2),0,cos(forceAngle+beltAngle+M_PI_2))));
            updatePlacement(sep, 2, SbVec3f(0, dia/8 + dia/2 * rat1, 0), SbRotation());
            const SoSeparator* subsep = static_cast<SoSeparator*>(sep->getChild(4));
            updateArrow(subsep, 0, dia/8 + dia/2 * rat1, dia/8);
            sep = static_cast<SoSeparator*>(pShapeSep->getChild(4));
            updatePlacement(sep, 0, SbVec3f(-dia/2 * sin(forceAngle-beltAngle), 0, -dia/2 * cos(forceAngle-beltAngle)),
                SbRotation(SbVec3f(0,1,0), SbVec3f(-sin(forceAngle-beltAngle-M_PI_2),0,-cos(forceAngle-beltAngle-M_PI_2))));
            updatePlacement(sep, 2, SbVec3f(0, dia/8 + dia/2 * rat2, 0), SbRotation());
            subsep = static_cast<SoSeparator*>(sep->getChild(4));
            updateArrow(subsep, 0, dia/8 + dia/2 * rat2, dia/8);
        }
    } else if ((strcmp(prop->getName(), "ForceAngle") == 0) || (strcmp(prop->getName(), "BeltAngle") == 0)) {
        if (pShapeSep->getNumChildren() > 0) {
            double radius = pcConstraint->Radius.getValue();
            double dia = pcConstraint->Diameter.getValue();
            if (dia < 2 * radius)
                dia = 2 * radius;
            double forceAngle = pcConstraint->ForceAngle.getValue() / 180 * M_PI;
            double beltAngle = pcConstraint->BeltAngle.getValue();

            const SoSeparator* sep = static_cast<SoSeparator*>(pShapeSep->getChild(3));
            updatePlacement(sep, 0, SbVec3f(dia/2 * sin(forceAngle+beltAngle), 0, dia/2 * cos(forceAngle+beltAngle)),
                SbRotation(SbVec3f(0,1,0), SbVec3f(sin(forceAngle+beltAngle+M_PI_2),0,cos(forceAngle+beltAngle+M_PI_2))));
            sep = static_cast<SoSeparator*>(pShapeSep->getChild(4));
            updatePlacement(sep, 0, SbVec3f(-dia/2 * sin(forceAngle-beltAngle), 0, -dia/2 * cos(forceAngle-beltAngle)),
                SbRotation(SbVec3f(0,1,0), SbVec3f(-sin(forceAngle-beltAngle-M_PI_2),0,-cos(forceAngle-beltAngle-M_PI_2))));
        }
    } else if ((strcmp(prop->getName(), "BeltForce1") == 0) || (strcmp(prop->getName(), "BeltForce2") == 0)) {
        if (pShapeSep->getNumChildren() > 0) {
            double radius = pcConstraint->Radius.getValue();
            double dia = pcConstraint->Diameter.getValue();
            if (dia < 2 * radius)
                dia = 2 * radius;
            double rat1 = 0.8, rat2 = 0.2;
            double f1 = pcConstraint->BeltForce1.getValue();
            double f2 = pcConstraint->BeltForce2.getValue();
            if (f1+f2 > Precision::Confusion()) {
                rat1 = f1 / (f1+f2);
                rat2 = f2 / (f1+f2);
            }

            const SoSeparator* sep = static_cast<SoSeparator*>(pShapeSep->getChild(3));
            updatePlacement(sep, 2, SbVec3f(0, dia/8 + dia/2 * rat1, 0), SbRotation());
            const SoSeparator* subsep = static_cast<SoSeparator*>(sep->getChild(4));
            updateArrow(subsep, 0, dia/8 + dia/2 * rat1, dia/8);
            sep = static_cast<SoSeparator*>(pShapeSep->getChild(4));
            updatePlacement(sep, 2, SbVec3f(0, dia/8 + dia/2 * rat2, 0), SbRotation());
            subsep = static_cast<SoSeparator*>(sep->getChild(4));
            updateArrow(subsep, 0, dia/8 + dia/2 * rat2, dia/8);
        }
    }

    ViewProviderFemConstraint::updateData(prop);
}
コード例 #30
0
void ViewProviderFemConstraintHeatflux::updateData(const App::Property* prop)
{
    // Gets called whenever a property of the attached object changes
    Fem::ConstraintHeatflux* pcConstraint = static_cast<Fem::ConstraintHeatflux*>(this->getObject());
    float scaledradius = RADIUS * pcConstraint->Scale.getValue(); //OvG: Calculate scaled values once only
    float scaledheight = HEIGHT * pcConstraint->Scale.getValue();
    //float ambienttemp = pcConstraint->AmbientTemp.getValue();
    ////float facetemp = pcConstraint->FaceTemp.getValue();
    //float filmcoef = pcConstraint->FilmCoef.getValue();

    if (strcmp(prop->getName(),"Points") == 0) {
        const std::vector<Base::Vector3d>& points = pcConstraint->Points.getValues();
        const std::vector<Base::Vector3d>& normals = pcConstraint->Normals.getValues();
        if (points.size() != normals.size())
            return;
        std::vector<Base::Vector3d>::const_iterator n = normals.begin();

        // Note: Points and Normals are always updated together
        pShapeSep->removeAllChildren();

        for (std::vector<Base::Vector3d>::const_iterator p = points.begin(); p != points.end(); p++) {
            //Define base and normal directions
            SbVec3f base(p->x, p->y, p->z);
            SbVec3f dir(n->x, n->y, n->z);//normal

            ///Temperature indication
            //define separator
            SoSeparator* sep = new SoSeparator();

            ///draw a temp gauge,with sphere and a cylinder
            //first move to correct position
            SoTranslation* trans = new SoTranslation();
            SbVec3f newPos=base+scaledradius*dir*0.7f;
            trans->translation.setValue(newPos);
            sep->addChild(trans);

            //adjust orientation
            SoRotation* rot = new SoRotation();
            rot->rotation.setValue(SbRotation(SbVec3f(0,1,0),dir));
            sep->addChild(rot);

            //define color of shape
            SoMaterial* myMaterial = new SoMaterial;
            myMaterial->diffuseColor.set1Value(0,SbColor(0.65f,0.1f,0.25f));//RGB
            //myMaterial->diffuseColor.set1Value(1,SbColor(.1,.1,.1));//possible to adjust sides separately
            sep->addChild(myMaterial);

            //draw a sphere
            SoSphere* sph = new SoSphere();
            sph->radius.setValue(scaledradius*0.75);
            sep->addChild(sph);
            //translate position
            SoTranslation* trans2 = new SoTranslation();
            trans2->translation.setValue(SbVec3f(0,scaledheight*0.375,0));
            sep->addChild(trans2);
            //draw a cylinder
            SoCylinder* cyl = new SoCylinder();
            cyl->height.setValue(scaledheight*0.5);
            cyl->radius.setValue(scaledradius*0.375);
            sep->addChild(cyl);
            //translate position
            SoTranslation* trans3 = new SoTranslation();
            trans3->translation.setValue(SbVec3f(0,scaledheight*0.375,0));
            sep->addChild(trans3);
            //define color of shape
            SoMaterial *myMaterial2 = new SoMaterial;
            myMaterial2->diffuseColor.set1Value(0,SbColor(1,1,1));//RGB
            sep->addChild(myMaterial2);
            //draw a cylinder
            SoCylinder* cyl2 = new SoCylinder();
            cyl2->height.setValue(scaledheight*0.25);
            cyl2->radius.setValue(scaledradius*0.375);
            sep->addChild(cyl2);
                        //translate position
            SoTranslation* trans4 = new SoTranslation();
            trans4->translation.setValue(SbVec3f(0,-scaledheight*0.375,0));
            sep->addChild(trans4);
                        //draw a cylinder
            SoCylinder* cyl3 = new SoCylinder();
            cyl3->height.setValue(scaledheight*0.05);
            cyl3->radius.setValue(scaledradius*1);
            sep->addChild(cyl3);

            pShapeSep->addChild(sep);

            n++;
        }
    }
    // Gets called whenever a property of the attached object changes
    ViewProviderFemConstraint::updateData(prop);
}