Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
r777 committed - cutsim work
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
opencam...@googlecode.com  
View profile  
 More options Jun 29 2011, 9:31 am
From: opencam...@googlecode.com
Date: Wed, 29 Jun 2011 13:31:22 +0000
Local: Wed, Jun 29 2011 9:31 am
Subject: [opencamlib] r777 committed - cutsim work
Revision: 777
Author:   anders.e.e.wallin
Date:     Wed Jun 29 06:30:31 2011
Log:      cutsim work

http://code.google.com/p/opencamlib/source/detail?r=777

Modified:
  /trunk/cpp_examples/cutsim1/cutsim.h
  /trunk/cpp_examples/cutsim2/cutsim.h
  /trunk/scripts/tsp_04.py
  /trunk/src/cutsim/volume.cpp
  /trunk/src/cutsim/volume.h

=======================================
--- /trunk/cpp_examples/cutsim1/cutsim.h        Wed Jun 29 06:19:20 2011
+++ /trunk/cpp_examples/cutsim1/cutsim.h        Wed Jun 29 06:30:31 2011
@@ -26,8 +26,8 @@
  /// the corresponding GLData surface which is used for rendering
  class Cutsim : public QObject {
      Q_OBJECT
-public:
-
+
+public:
      // std::cout << ocl::revision() << "\n";
      // std::cout << " Experimental C++ cutting simulation.\n";
      // Octree(root_scale, max_depth, cp)
@@ -39,17 +39,29 @@

          std::cout << "running init(3) on the octree. this splits the cube  
three times. \n";
          std::cout << "we go from 1 cube -> 8 -> 64 -> 512 cubes \n";
-        tree->init(5u);
-        tree->debug=true;
+        tree->init(3u);
+        tree->debug=false;
          std::cout << " tree after init: " << tree->str() << "\n";
-
          ocl::CubeVolume cube;
-        cube.side = 4.0;
-        cube.invert = false;
+        cube.side = 3.5;
          cube.calcBB();

+        //ocl::PlaneVolume px_plus(true, 0u, -7);
+        //ocl::PlaneVolume px_minus(false, 0u, 7);
+
+        //ocl::PlaneVolume py_plus(true, 1u, -7);
+        //ocl::PlaneVolume py_minus(false, 1u, 7);
+
+        //ocl::PlaneVolume pz_plus(true, 2u, -7);
+        //ocl::PlaneVolume pz_minus(false, 2u, 7);
+
          tree->diff_negative( &cube);
-
+        //tree->diff_negative( &px_plus  );
+        //tree->diff_negative( &px_minus );
+        //tree->diff_negative( &py_plus  );
+        //tree->diff_negative( &py_minus );
+        //tree->diff_negative( &pz_plus  );
+        //tree->diff_negative( &pz_minus );
          std::cout << " tree after stock-cut: " << tree->str() << "\n";
          mc = new ocl::MarchingCubes();
      }
@@ -62,11 +74,9 @@
      }
      void updateGL() {
          // traverse the octree and update the GLData correspondingly
-        std::cout << " tree->updateGL() \n";
-        std::cout << " tree before updateGL(): " << tree->str() << "\n";
-        tree->updateGL();
-    }
-    /*
+        ocl::Octnode* root = tree->getRoot();
+        updateGL(root);
+    }
      void updateGL(ocl::Octnode* current) {
          // starting at current, update the isosurface
          if ( current->isLeaf() && current->surface() && !current->valid()  
) {
@@ -103,9 +113,8 @@
                  }
              }
          }
-    } */
-
-    /*
+    }
+
      void surf() {
          // run mc on all nodes
          // std::vector<Triangle> mc_node(const Octnode* node);
@@ -113,7 +122,7 @@
          tree->updateGL();
          //tris = mc->mc_tree( tree ); // this gets ALL triangles from the  
tree and stores them here.
          //std::cout << " mc() got " << tris.size() << " triangles\n";
-    }*/
+    }

      //std::vector<ocl::Triangle> getTris() {
      //    return tris;
@@ -123,10 +132,13 @@
      void cut() { // demo slot of doing a cutting operation on the tree  
with a volume.
          std::cout << " cut! called \n";
          ocl::SphereOCTVolume s;
-        s.radius = 1;
-        s.center = ocl::Point(3,3,3);
+        s.radius = 3;
+        s.center = ocl::Point(7,7,7);
          s.calcBB();
+        //std::cout << " before diff: " << tree->str() << "\n";
          tree->diff_negative( &s );
+        //std::cout << " AFTER diff: " << tree->str() << "\n";
+
          updateGL();
      }
  private:
=======================================
--- /trunk/cpp_examples/cutsim2/cutsim.h        Wed Jun 29 06:19:20 2011
+++ /trunk/cpp_examples/cutsim2/cutsim.h        Wed Jun 29 06:30:31 2011
@@ -60,11 +60,10 @@
          unsigned int max_depth = 7;
          tree = new ocl::Octree(10.0, max_depth, octree_center );
          std::cout << " tree before init: " << tree->str() << "\n";
-        tree->init(3u);
+        tree->init(2u);
          tree->debug=false;
          std::cout << " tree after init: " << tree->str() << "\n";

-        /*
          ocl::SphereOCTVolume stock_sphere;
          stock_sphere.radius = 7;
          stock_sphere.center = ocl::Point(0,0,0);
@@ -72,19 +71,22 @@
          stock_sphere.invert = true;

          tree->diff_negative( &stock_sphere );
-        */
-        ocl::CubeVolume cube;
-        cube.side = 11.0;
-        cube.invert = true;
-        cube.calcBB();
-        tree->diff_negative( &cube);
-
-
-        std::cout << " tree after sphere-cut: " << tree->str() << "\n";
+
+        std::cout << " tree after pane-cut: " << tree->str() << "\n";
+
+        /*
+        ocl::SphereOCTVolume s;
+        s.radius = 2;
+        s.center = ocl::Point(4,4,4);
+        s.calcBB();
+        std::cout << " before diff: " << tree->str() << "\n";
+        tree->diff_negative( &s );
+        std::cout << " AFTER diff: " << tree->str() << "\n";
+        */

          mc = new ocl::MarchingCubes();
          tree->setIsoSurf(mc);
-
+        //tree->debug=true;
      }
      void setGLData(ocl::GLData* gldata) {
          // this is the GLData that corresponds to the tree
@@ -97,7 +99,6 @@
      void updateGL() {
          // traverse the octree and update the GLData correspondingly
          tree->updateGL();
-        std::cout << " updateGL() \n";
      }

  public slots:
=======================================
--- /trunk/scripts/tsp_04.py    Wed Jun 29 06:19:20 2011
+++ /trunk/scripts/tsp_04.py    Wed Jun 29 06:30:31 2011
@@ -61,3 +61,66 @@

+import ocl
+import camvtk
+import time
+import vtk
+import datetime
+import math
+import gzip
+import csv
+
+
+def readPts():
+    spamReader = csv.reader(open('tsplib/graph.txt', 'rb'), delimiter=',',  
quotechar='|')
+    pts=[]
+    for row in spamReader:
+        pts.append( ocl.Point( float(row[0]), float(row[1]) ) )
+    return pts
+
+def drawTour(myscreen, pts, tour, tourColor = camvtk.red):
+    for n in range(0,len(tour)-1):
+        idx0 = n
+        idx1 = n+1
+        ip1 = pts[ tour[idx0] ]
+        ip2 = pts[ tour[idx1] ]
+        myscreen.addActor(  
camvtk.Line(p1=(ip1.x,ip1.y,ip1.z),p2=(ip2.x,ip2.y,ip2.z), color=tourColor)  
)
+
+def drawPoints(myscreen, pts):
+    c=camvtk.PointCloud( pts )
+    c.SetPoints()
+    myscreen.addActor(c )
+
+
+if __name__ == "__main__":
+
+    myscreen = camvtk.VTKScreen()
+
+
+    tsp = ocl.TSPSolver()
+    pts = readPts()
+    drawPoints(myscreen, pts)
+    print "got ",len(pts)," points"
+    #exit()
+    for p in pts:
+        tsp.addPoint( p.x , p.y)
+    start_time = time.time()
+    tsp.run()
+    run_time = time.time() - start_time
+    l = tsp.getLength()
+    print "tour length ",l
+    out = tsp.getOutput()
+    for o in out:
+        print o,
+
+    drawTour(myscreen, pts, out)
+
+    myscreen.camera.SetPosition(0.0, 0.0, 200)
+    myscreen.camera.SetViewUp(0.0, 0.0, 0)
+    myscreen.camera.SetFocalPoint(50, 50, 0)
+    myscreen.render()
+
+    myscreen.iren.Start()
+
+
+
=======================================
--- /trunk/src/cutsim/volume.cpp        Wed Jun 29 06:19:20 2011
+++ /trunk/src/cutsim/volume.cpp        Wed Jun 29 06:30:31 2011
@@ -81,7 +81,6 @@
  CubeVolume::CubeVolume() {
      center = Point(0,0,0);
      side = 1.234;
-    invert = false;
  }

  /// set bbox values
@@ -94,15 +93,20 @@
  }

  double CubeVolume::dist(Point& p) const {
-    // from:  
http://reocities.com/SiliconValley/port/3456/isosurf/isosurfaces.html
-    double d =  std::max( square(p.x)-square(side/2), std::max(  
square(p.y)-square(side/2), square(p.z)-square(side/2) ) );
-    if (invert)
-        return -d;
-    else
-        return d;
+    double m;
+    m = p.x;
+    if ( fabs(m) < fabs(p.y) )
+        m = p.y;
+    if (fabs(m) < fabs(p.z) )
+        m = p.z;
+    // m is now the maximum coordinate
+    return -(m-side);
+
+    //return 0;
  }

-bool CubeVolume::isInside(Point& p) const {
+bool CubeVolume::isInside(Point& p) const
+{
      bool x,y,z;
      x = ( (p.x >= (center.x-side/2)) && (p.x <= (center.x+side/2)) );
      y = ( (p.y >= (center.y-side/2)) && (p.y <= (center.y+side/2)) );
=======================================
--- /trunk/src/cutsim/volume.h  Wed Jun 29 06:19:20 2011
+++ /trunk/src/cutsim/volume.h  Wed Jun 29 06:30:31 2011
@@ -93,7 +93,7 @@
          /// update bounding-box
          void calcBB();
          double dist(Point& p) const;
-        bool invert;
+        // {return -1;}
  };

  /// cylinder volume


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »