Announcement

Collapse
No announcement yet.

After CSG operation I need change my bounding box to right operant

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • After CSG operation I need change my bounding box to right operant

    Hi,

    I have scenario that after CSG operation I need change my bounding box to right operant , but currently it getting left operand

    I come across the Documentation to the scenario by SoGetBoundingBoxAction ,The documentation say about :
    /************************************************** ************************************************** ************************************************** *****************************************
    Each bounding box is calculated as an SbXfBox3f, where the transformation matrix is defined so that the bounding box can be stored in the object space of the SoShape. When two bounding boxes are combined by a group node, the combination is performed so as to produce the smaller untransformed box. The result of the calculation by the action can be returned as an SbXfBox3f or as a world-space-aligned SbBox3f.

    To calculate the bounding box of a subgraph bounded by two paths, specify the left edge of the subgraph with setResetPath(), and apply the action to the path that defines the right edge of the subgraph. The accumulated bounding box and transformation will be reset when the tail of the reset path is traversed.
    If the subgraph being traversed does not contain any shapes, the returned bounding box will be empty (that is, SbBox3f.isEmpty() will return true).
    ************************************************** ************************************************** ************************************************** *******************************************/

    My Question is it any relation to manipulate bounding box by setResetPath() Method from SoGetBoundingBoxAction , ? I was tried with this method but not I am successful, if it is relevant can you please send me some sample code

    #Note :
    I was tried following way using the method of setResetPath()

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;

    using OIV.Inventor.Nodes;
    using OIV.Inventor.Win;
    using OIV.Inventor.Win.Viewers;
    using OIV.Inventor;
    using OIV.Inventor.Actions;
    using OIV.IvTune;

    namespace _02_4_Examiner
    {
    public partial class MainForm : Form
    {
    SoWinExaminerViewer myViewer;

    public MainForm()
    {
    InitializeComponent();
    CreateSample();
    }

    public void CreateSample()
    {
    SoSeparator root = new SoSeparator();

    myViewer = new SoWinExaminerViewer(this, "", true,
    SoWinFullViewer.BuildFlags.BUILD_ALL, SoWinViewer.Types.BROWSER);
    myViewer.SetSceneGraph(root);
    myViewer.SetTitle("Examiner Viewer");
    SoIvTune.Start(root);

    // separator hold the cylinder properties
    SoSeparator sepCylinder = new SoSeparator();
    sepCylinder.SetName("sepCylinder");
    SoRotation myRot = new SoRotation();
    myRot.rotation.SetValue(new SbVec3f(0.0f, 0.0f, 1.0f), 3.1415f / 4.0f);
    sepCylinder.AddChild(myRot);
    // root.AddChild(myRot);

    SoMaterial myMaterial = new SoMaterial();
    myMaterial.diffuseColor.SetValue(new SbVec3f(1.0f, 0.0f, 0.0f));
    root.AddChild(myMaterial);


    SoCylinder myCyl = new SoCylinder();
    myCyl.radius.Value = 1.5f;
    myCyl.height.Value = 0.5f;
    // root.AddChild(myCyl);
    // myCyl.height.Value = 2.0f;
    sepCylinder.AddChild(myCyl);
    // root.AddChild(sepCylinder);

    SoCube cube = new SoCube();
    cube.height.Value = 2.0f;
    cube.depth.Value = 2.5f;
    cube.width.Value = 1.5f;

    // root.AddChild(cube);

    SoCSGShape myCSG = new SoCSGShape();
    myCSG.SetName("myCSG");

    myCSG.leftOperand.Value = (cube);

    myCSG.rightOperand.Value = (sepCylinder);
    myCSG.csgOperation.Value = SoCSGShape.CsgOperationTypes.INTERSECTION;
    root.AddChild(myCSG);

    SoGetBoundingBoxAction gba = new SoGetBoundingBoxAction(myViewer.GetViewportRegion( ));

    // gba.Apply(root);
    gba.Apply(myCSG);

    // changing bounding box


    SoSearchAction mySearcAction2 = new SoSearchAction();
    mySearcAction2.SetNode(sepCylinder);
    mySearcAction2.SetSearchingAll(true);
    mySearcAction2.SetFind((int)SoSearchAction.LookFor s.NAME);
    mySearcAction2.SetName("sepCylinder");
    mySearcAction2.Apply(root);


    SoPath pathSub2 = mySearcAction2.GetPath();

    Console.WriteLine("fulll path");
    SoGetBoundingBoxAction bbActionSub2 = new SoGetBoundingBoxAction(myViewer.GetViewportRegion( ));
    //

    bbActionSub2.SetResetPath(pathSub2, true, SoGetBoundingBoxAction.ResetTypes.BBOX);//bBoxImplant
    bbActionSub2.Apply(root);



    /// changing bounding box
    SbXfBox3f xfbbox = gba.GetXfBoundingBox();
    float xmin, ymin, zmin, xmax, ymax, zmax;
    xfbbox.GetBounds(out xmin, out ymin, out zmin, out xmax, out ymax, out zmax);

    SoMaterial myMaterial2 = new SoMaterial();
    myMaterial2.diffuseColor.SetValue(1.0f, 1.0f, 1.0f);
    root.AddChild(myMaterial2);

    SoCoordinate3 myCoord = new SoCoordinate3();
    myCoord.point.Set1Value(0, xmin, ymin, zmin);
    myCoord.point.Set1Value(1, xmax, ymin, zmin);
    myCoord.point.Set1Value(2, xmax, ymax, zmin);
    myCoord.point.Set1Value(3, xmin, ymax, zmin);
    myCoord.point.Set1Value(4, xmin, ymin, zmin);

    SoLineSet myLSet = new SoLineSet();
    myLSet.numVertices.SetValue(5);
    root.AddChild(myCoord);
    root.AddChild(myLSet);

    SoCoordinate3 myCoord2 = new SoCoordinate3();
    myCoord2.point.Set1Value(0, xmin, ymin, zmax);
    myCoord2.point.Set1Value(1, xmax, ymin, zmax);
    myCoord2.point.Set1Value(2, xmax, ymax, zmax);
    myCoord2.point.Set1Value(3, xmin, ymax, zmax);
    myCoord2.point.Set1Value(4, xmin, ymin, zmax);

    SoLineSet myLSet2 = new SoLineSet();
    myLSet2.numVertices.SetValue(5);
    root.AddChild(myCoord2);
    root.AddChild(myLSet2);


    }
    }
    }
Working...
X