コード例 #1
0
ファイル: STL.cpp プロジェクト: rsingla92/aegle
Facet STL::getFacetAt(const int& i) const
{
    if(isFacetIndexValid(i))
    {
        return Facet();
    }

    return facets_[i];
}
コード例 #2
0
ファイル: geom_ops.cpp プロジェクト: venkat78/agrid
  _TMESH_TMPL_TYPE
  VOID _TMESH_TMPL_DECL::GetFacetVertices(iFACET facetIndex, eCOORD coord, REAL coordVal, iVERTEX v[2])
  {

    cHALF_EDGE* facetHes[2] = { NULL, NULL };
    BOOL verticesAreNew[2] = { false, false };

    cHALF_EDGE *startingHe = Facet(facetIndex)->FindMinHalfEdge(coord);
    cHALF_EDGE *currHe = startingHe;

    INT i = 0;
    do {
      cPOINT3 tailPoint = currHe->Tail()->Point();
      cPOINT3 headPoint = currHe->Head()->Point();

      REAL heTailCoord = tailPoint[coord];
      REAL heHeadCoord = headPoint[coord];

      REAL diff1 = coordVal - heTailCoord;
      REAL diff2 = heHeadCoord - coordVal;

      if(fabs(diff2) < cLIMITS::Tolerance()) {
	currHe = currHe->Next();
	continue;
      }

      if(fabs(diff1) < cLIMITS::Tolerance())
	v[i++] = currHe->Tail()->Index();
      else if(diff1 * diff2 > 0.0) {
	cPOINT3 newPoint = ((tailPoint*diff2) + (headPoint*diff1))/(diff1+diff2);
	v[i++] = NewVertex(newPoint);
	facetHes[i-1] = currHe;
	verticesAreNew[i-1] = true;
      }

      if(i == 2) break;

      currHe = currHe->Next();
    } while( currHe != startingHe);

    if(verticesAreNew[0])
      SplitEdge(v[0], facetHes[0]->Tail()->Index(),
		facetHes[0]->Head()->Index());

    if(verticesAreNew[1])
      SplitEdge(v[1], facetHes[1]->Tail()->Index(),
		facetHes[1]->Head()->Index());
  }
コード例 #3
0
ファイル: Obstacle.cpp プロジェクト: xammi/Curs_Fire
void Obstacle::buildDefault() {
    Point3D left(lX, lY, lZ),
            right(rX, rY, rZ);

    Vector3D dX(rX - lX, 0, 0),
             dY(0, rY - lY, 0),
             dZ(0, 0, rZ - lZ);

    tops = {left, left + dX, left + dY, left + dZ,
            right - dZ, right - dX, right - dY, right};

    edges = { Edge(0,1), Edge(0,2), Edge(0,3), Edge(1,4),
              Edge(1,6), Edge(2,4), Edge(2,5), Edge(3,5),
              Edge(3,6), Edge(4,7), Edge(5,7), Edge(6,7) };

    facets = { Facet({ 0, 1, 4, 2 }), Facet({ 0, 1, 6, 3 }), Facet({ 0, 2, 5, 3 }),
               Facet({ 1, 4, 7, 6 }), Facet({ 2, 4, 7, 5 }), Facet({ 3, 6, 7, 5 }) };
}
コード例 #4
0
ファイル: volume.cpp プロジェクト: Asuzer/cgal
void Volume::display_marchin_cube()
{
#ifdef CGAL_SURFACE_MESH_DEMO_USE_MARCHING_CUBE
  if(m_surface_mc.empty())
  {
    QTime total_time;
    total_time.start();

    values_list->save_values(fileinfo.absoluteFilePath());

    unsigned int nx = m_image.xdim();
    unsigned int ny = m_image.ydim();
    unsigned int nz = m_image.zdim();
    if(nx * ny * nz == 0)
    {
      status_message("No volume loaded.");
      return;
    }

    mc_timer.reset();
    busy();
    status_message("Marching cubes...");

    mc_timer.start();
    m_surface_mc.clear();

    if(mc.ntrigs()!=0)
      mc.clean_all();
    mc.set_resolution(nx,ny,nz);
    mc.init_all();
    mc.set_ext_data(static_cast<unsigned char*>(m_image.image()->data));

    nbs_of_mc_triangles.resize(values_list->numberOfValues());

    for(int value_id = 0; 
        value_id < values_list->numberOfValues();
        ++value_id)
    {
      status_message(tr("Marching cubes, isovalue #%1...").arg(value_id));

      // set data
//       for(unsigned int i=0;i<nx;i++)
//         for(unsigned int j=0;j<ny;j++)
//           for(unsigned int k=0;k<nz;k++)
//           {
//             const float& value = m_image.value(i,j,k);
//             mc.set_data(value,i,j,k);
//           }
      // compute scaling ratio
      if(value_id > 0)
        mc.init_temps();
      mc.run(values_list->value(value_id),
             m_image.vx(),
             m_image.vy(),
             m_image.vz());
      mc.clean_temps();

      std::vector<double> facets;
      mc.get_facets(facets);

      mc_timer.stop();
      const unsigned int begin = value_id == 0 ? 0 : nbs_of_mc_triangles[value_id-1];
      const unsigned int nbt = facets.size() / 9;
      for(unsigned int i=begin;i<nbt;i++)
      {
        const Point a(facets[9*i],   facets[9*i+1], facets[9*i+2]);
        const Point b(facets[9*i+3], facets[9*i+4], facets[9*i+5]);
        const Point c(facets[9*i+6], facets[9*i+7], facets[9*i+8]);
        const Triangle_3 t(a,b,c);
        const Vector u = t[1] - t[0];
        const Vector v = t[2] - t[0];
        Vector n = CGAL::cross_product(u,v);
        n = n / std::sqrt(n*n);
        m_surface_mc.push_back(Facet(t,n,values_list->item(value_id)));
      }
      nbs_of_mc_triangles[value_id]=m_surface_mc.size();
      mc_timer.start();
    }
    mc_timer.stop();
    not_busy();
    mc_total_time = total_time.elapsed();

    // invalidate the display list
    lists_draw_surface_mc_is_valid = false;
    list_draw_marching_cube_is_valid = false;
  }
  CGAL::Bbox_3 bbox(0,0,0,0,0,0);
  for(std::vector<Facet>::const_iterator
        it = m_surface_mc.begin(), end = m_surface_mc.end();
      it != end; ++it)
  {
    bbox = bbox + it->get<0>().bbox();
  }

  m_view_mc = true;
  m_view_surface = false;
  Q_EMIT changed();
  if(!m_surface_mc.empty())
  {
    Q_EMIT new_bounding_box(bbox.xmin(),
                          bbox.ymin(),
                          bbox.zmin(),
                          bbox.xmax(),
                          bbox.ymax(),
                          bbox.zmax());
  }
  status_message(tr("Marching cubes done. %2 facets in %1s (CPU time), total time is %3s.")
                 .arg(mc_timer.time())
                 .arg(m_surface_mc.size())
                 .arg(mc_total_time/1000.));

  save_image_settings(fileinfo.absoluteFilePath());
#endif // CGAL_SURFACE_MESH_DEMO_USE_MARCHING_CUBE
}
コード例 #5
0
ファイル: geom_ops.cpp プロジェクト: venkat78/agrid
  _TMESH_TMPL_TYPE
  iFACET _TMESH_TMPL_DECL::Clip(iFACET facetIndex, const cSEGMENT3 &cut)
  {
    cFACET* facet = Facet(facetIndex);

    if(facet == NULL || facet->IsDeleted())
      return INVALID_IFACET;

    iVERTEX cutVertices[2] = { INVALID_IVERTEX, INVALID_IVERTEX };
    BOOL insertCutVertices[2] = { false, false };
    cPOINT3 points[2];
    cEDGE splitEdges[2];

    const cPOINT3 &cutTail = cut.Source();
    const cPOINT3 &cutHead = cut.Target();

    typename cFACET::half_edge_circulator currFacetHe = facet->HalfEdgesBegin();
    typename cFACET::half_edge_circulator lastFacetHe = facet->HalfEdgesEnd();

    INT numCuts = 0;
    for( ; currFacetHe != lastFacetHe ; currFacetHe++) {
      cSEGMENT3 heSegment = currFacetHe->Segment();

      if(heSegment.HasOn(cutTail)) {
        if(!(heSegment.Target() == cutTail)) {
          if(heSegment.Source() == cutTail) {
            cutVertices[numCuts++] = currFacetHe->Tail()->Index();
          }
          else {
            insertCutVertices[numCuts] = true;

            splitEdges[numCuts].v1 = currFacetHe->Tail()->Index();
            splitEdges[numCuts].v2 = currFacetHe->Head()->Index();

            points[numCuts] = cutTail;
            numCuts++;
          }
        }
      }

      if(heSegment.HasOn(cutHead)) {
        if(!(heSegment.Target() == cutHead)) {
          if(heSegment.Source() == cutHead) {
            cutVertices[numCuts++] = currFacetHe->Tail()->Index();
          }
          else {
            insertCutVertices[numCuts] = true;

            splitEdges[numCuts].v1 = currFacetHe->Tail()->Index();
            splitEdges[numCuts].v2 = currFacetHe->Head()->Index();

            points[numCuts] = cutHead;
            numCuts++;
          }
        }
      }

      if(numCuts == 2)
        break;
    }

    //Cuts found.
    assert(numCuts == 2);
    if(numCuts != 2)
      return INVALID_IFACET;

    if(insertCutVertices[0]) {
      cutVertices[0] = NewVertex(points[0]);
      SplitEdge(cutVertices[0], splitEdges[0].v1, splitEdges[0].v2);
    }

    if(insertCutVertices[1]) {
      cutVertices[1] = NewVertex(points[1]);
      SplitEdge(cutVertices[1], splitEdges[1].v1, splitEdges[1].v2);
    }

    return InsertDiagonal(facetIndex, cutVertices[0], cutVertices[1]);
  }
コード例 #6
0
ファイル: smax.cpp プロジェクト: SoumyajitG/VolRoverN
void
grow_maximum(Cell_handle c_max, 
             Triangulation& triang, 
             map<int, cell_cluster> &cluster_set)
{
   // mark it visited.
   c_max->visited = true;
   cluster_set[c_max->id].in_cluster = true;
   cluster_set[c_max->id].outside = c_max->outside;

   // Now grow the maximum through the other tetrahedra.
   vector<Facet> bdy_stack;
   for(int i = 0; i < 4; i ++)
      bdy_stack.push_back(Facet(c_max, i));
   while(! bdy_stack.empty())
   {
      Cell_handle old_c = bdy_stack.back().first;
      int old_id = bdy_stack.back().second;
      bdy_stack.pop_back();
      CGAL_assertion(old_c->visited);
      CGAL_assertion(cluster_set[old_c->id].in_cluster);

      #ifndef __INSIDE__
      CGAL_assertion( old_c->outside );
      #endif

      #ifndef __OUTSIDE__
      CGAL_assertion( ! old_c->outside );
      #endif

      Cell_handle new_c = old_c->neighbor(old_id);
      int new_id = new_c->index(old_c);

      // If the new_c is infinite then no point in checking
      // the flow.
      if(triang.is_infinite(new_c))
         continue;
      // if the flow hits the surface continue.
      // if( old_c->outside != new_c->outside)
         // continue;
      // If new_c is already visited continue.
      if(new_c->visited) 
         continue;

      // collect new_c only if new_c flows into old_c via the
      // facet in between.
      if( is_outflow(Facet(new_c, new_id)) )
      {
         // CGAL_assertion( !is_outflow(Facet(old_c, old_id)));
         if(is_outflow(Facet(old_c, old_id))) continue;
         
         // new_c has to satisfy the following.
         CGAL_assertion( !is_maxima(new_c) && !new_c->visited &&
                         !triang.is_infinite(new_c));
         
         new_c->visited = true;
         cluster_set[new_c->id].in_cluster = true;
         cluster_set[new_c->id].outside = c_max->outside;

         // put the cells accessible via new_c into bdy_stack.
         for(int i = 1; i < 4; i ++)
         {
            if(new_c->neighbor((new_id+i)%4)->visited) 
	       continue;
	    bdy_stack.push_back(Facet(new_c, (new_id+i)%4));
         }
         // put new_c into the current cluster.
         // In other words merge the current cluster and the cluster owned by
         // new_c (as it is initialized).
         add_cell_to_cluster(cluster_set, c_max->id, new_c->id);
      }
   }
}
コード例 #7
0
ファイル: OGL.cpp プロジェクト: t-doi/OpenGL-freeglut
//---------------------------------------------------------------------------
void OGL::Facet(double x0,double y0,double z0,
                       double x1,double y1,double z1,
                       double x2,double y2,double z2)
{
	Facet(x0,y0,z0,x1,y1,z1,x2,y2,z2);
}
コード例 #8
0
ファイル: pfld_test_io.cpp プロジェクト: igorcerovsky/pfld
void GetFacets(pfld::facet_vec& facets, const std::string sfile, const int n, bool bGenerate /*= false*/)
{
	if (bGenerate)
	{
		std::cout << "creating random facets..." << "\n";
		std::srand(1);
		for (int i = 0; i < n; ++i)
		{
			ptvec v{ point(rand() % 1001, rand() % 1001, -(rand() % 1001)),
				point(rand() % 1001, rand() % 1001, -rand() % 1001),
				point(rand() % 1001, rand() % 1001, -rand() % 1001) };
			facets.emplace_back(Facet(v));
		}

		std::ofstream file(sfile, std::ios::out);
		if (file.is_open())
		{
			int i = 0;
			for (auto it = facets.begin(); it != facets.end(); ++it)
			{
				ptvec& fpts = it->Data();
				file << "Facet " << i << " " << fpts.size() << "\n";
				for (auto itp = fpts.begin(); itp != fpts.end(); ++itp)
					file << itp->x << " " << itp->y << " " << itp->z << " ";
				file << "\n";
				i++;
			}
			file.close();
		}
	}
	else
	{
		std::cout << "loading facets..." << "\n";
		std::ifstream file(sfile, std::ios_base::in);
		if (file.is_open())
		{
			std::string stmp;
			ptvec v(3);
			int loadedFacets = 0;
			while (std::getline(file, stmp))
			{
				std::istringstream buffer(stmp);
				if (stmp.find("Facet") != std::string::npos)
				{
					// facet data
				}
				else
				{
					std::vector<double> vln{ std::istream_iterator<double>(buffer),
						std::istream_iterator<double>() };
					for (unsigned i = 0; i < vln.size() / 3; ++i)	{
						v[i] = point(vln[i * 3 + 0], vln[i * 3 + 1], vln[i * 3 + 2]);
					}
					facets.emplace_back(Facet(v));
					loadedFacets++;
					if (loadedFacets >= n)
						break;
				}
			}
			file.close();
		}
		std::cout << "loaded " << facets.size() << " facets." << "\n";
	}
}