// Gets cell numbers of all polyHedra
void Foam::readerDatabase::getPolyHedra()
{
    const cellModel& tet = *(cellModeller::lookup("tet"));
    const cellModel& pyr = *(cellModeller::lookup("pyr"));
    const cellModel& prism = *(cellModeller::lookup("prism"));
    const cellModel& wedge = *(cellModeller::lookup("wedge"));
    const cellModel& tetWedge = *(cellModeller::lookup("tetWedge"));
    const cellModel& hex = *(cellModeller::lookup("hex"));

    DynamicList<label> polys(mesh().nCells()/100 + 1);

    const cellShapeList& cellShapes = mesh().cellShapes();

    forAll(cellShapes, celli)
    {
        const cellShape& cellShape = cellShapes[celli];
        const cellModel& cellModel = cellShape.model();

        if
        (
            (cellModel != tet)
         && (cellModel != pyr)
         && (cellModel != prism)
         && (cellModel != wedge)
         && (cellModel != tetWedge)
         && (cellModel != hex)
        )
        {
            polys.append(celli);
        }
    }

    Info<< "Found " << polys.size() << " polyhedral cells " << endl;
    polys_.transfer(polys);
}
void TestQgsDistanceArea::collections()
{
  //test measuring for collections
  QgsDistanceArea myDa;
  myDa.setSourceAuthId( "EPSG:4030" );
  myDa.setEllipsoidalMode( true );
  myDa.setEllipsoid( "WGS84" );

  //collection of lines, should be sum of line length
  QgsGeometry lines( QgsGeometryFactory::geomFromWkt( "GeometryCollection( LineString(0 36.53, 5.76 -48.16), LineString(0 25.54, 24.20 36.70) )" ) );
  double result = myDa.measureLength( &lines );
  QGSCOMPARENEAR( result, 12006159, 1 );
  result = myDa.measureArea( &lines );
  QVERIFY( qgsDoubleNear( result, 0 ) );

  //collection of polygons
  QgsGeometry polys( QgsGeometryFactory::geomFromWkt( "GeometryCollection( Polygon((0 36.53, 5.76 -48.16, 0 25.54, 0 36.53)), Polygon((10 20, 15 20, 15 10, 10 20)) )" ) );
  result = myDa.measureArea( &polys );
  QGSCOMPARENEAR( result, 670434859475LL, 1 );
  result = myDa.measureLength( &polys );
  QVERIFY( qgsDoubleNear( result, 0 ) );

  //mixed collection
  QgsGeometry mixed( QgsGeometryFactory::geomFromWkt( "GeometryCollection( LineString(0 36.53, 5.76 -48.16), LineString(0 25.54, 24.20 36.70), Polygon((0 36.53, 5.76 -48.16, 0 25.54, 0 36.53)), Polygon((10 20, 15 20, 15 10, 10 20)) )" ) );
  //measure area specifically
  result = myDa.measureArea( &mixed );
  QGSCOMPARENEAR( result, 670434859475LL, 1 );
  //measure length
  result = myDa.measureLength( &mixed );
  QGSCOMPARENEAR( result, 12006159, 1 );
}
Example #3
0
vector<Poly> Clipping::getPolys(const CL::Polygons &cpolys, double z, double extrusionfactor)
{
  uint count = cpolys.size();
  vector<Poly> polys(count);
  for (uint i = 0 ; i<count;  i++)
    polys[i] = getPoly(cpolys[i], z, extrusionfactor);
  return polys;
}
Example #4
0
void
IsValidOp::checkValid(const MultiPolygon *g)
{
	unsigned int ngeoms = g->getNumGeometries();
	vector<const Polygon *>polys(ngeoms);

	for (unsigned int i=0; i<ngeoms; ++i)
	{
		const Polygon *p = (const Polygon *)g->getGeometryN(i);

		checkInvalidCoordinates(p);
		if (validErr != NULL) return;

		checkClosedRings(p);
		if (validErr != NULL) return;

		polys[i]=p;
	}

	GeometryGraph graph(0,g);

	checkTooFewPoints(&graph);
	if (validErr!=NULL) return;

	checkConsistentArea(&graph);
	if (validErr!=NULL) return;

	if (!isSelfTouchingRingFormingHoleValid)
	{
		checkNoSelfIntersectingRings(&graph);
		if (validErr!=NULL) return;
	}

	for(unsigned int i=0; i<ngeoms; ++i)
	{
		const Polygon *p=polys[i]; 
		checkHolesInShell(p, &graph);
		if (validErr!=NULL) return;
	}

	for(unsigned int i=0; i<ngeoms; ++i)
	{
		const Polygon *p=polys[i];
		checkHolesNotNested(p, &graph);
		if (validErr!=NULL) return;
	}

	checkShellsNotNested(g,&graph);
	if (validErr!=NULL) return;

	checkConnectedInteriors(graph);
}
Example #5
0
bool WireComputer::process( TriangleSet * triangleSet ) {
  GEOM_ASSERT(triangleSet);
  GeometryArrayPtr polys(new GeometryArray);
  for(Index3Array::const_iterator _it = triangleSet->getIndexList()->begin();
  _it != triangleSet->getIndexList()->end(); _it++){
	Point3ArrayPtr points(new Point3Array);
	for(Index3::const_iterator _i = _it->begin(); _i != _it->end(); _i++){
	  points->push_back(triangleSet->getPointList()->getAt(*_i));
	}
	points->push_back(triangleSet->getPointList()->getAt(*(_it->begin())));
	polys->push_back(GeometryPtr(new Polyline(points)));
  }
  if(polys->empty())__wire = GeometryPtr();
  else if(polys->size() == 1)__wire = polys->getAt(0);
  else __wire = GeometryPtr(new Group(polys));
  return true;
}
Example #6
0
GeneralPolygon::operator ClipperLib::Polygons()
{
	ClipperLib::Polygons polys(_contours.size());
	for(unsigned int c=0; c < _contours.size() ; ++c)
	{
		const Contour &contour = _contours[c];
		ClipperLib::Polygon poly(contour.size());

		for(unsigned int v=0; v < contour.size() ; ++v)
		{
			sf::Vector2f worldPos = _transformFromLocalToWorld(contour[v]);
			poly[v] = ClipperLib::IntPoint(worldPos.x * clipperScaleCoeficient, worldPos.y * clipperScaleCoeficient);
		}

		polys[c] = poly;
	}
	return polys;
}
Example #7
0
bool WireComputer::process( QuadSet * quadSet ) {
  GEOM_ASSERT(quadSet);
  // nothing to do as quadSet is already an ExplicitModel
  GeometryArrayPtr polys(new GeometryArray);
  for(Index4Array::const_iterator _it = quadSet->getIndexList()->begin();
  _it != quadSet->getIndexList()->end(); _it++){
	Point3ArrayPtr points(new Point3Array);
	for(Index4::const_iterator _i = _it->begin(); _i != _it->end(); _i++){
	  points->push_back(quadSet->getPointList()->getAt(*_i));
	}
	points->push_back(quadSet->getPointList()->getAt(*(_it->begin())));
	polys->push_back(GeometryPtr(new Polyline(points)));
  }
  if(polys->empty())__wire = GeometryPtr();
  else if(polys->size() == 1)__wire = polys->getAt(0);
  else __wire = GeometryPtr(new Group(polys));
  return true;
}
Example #8
0
bool WireComputer::process( AmapSymbol * amapSymbol ) {
  GEOM_ASSERT(amapSymbol);
  // nothing to do as amapSymbol has a cached representation of type of Mesh.
  GeometryArrayPtr polys(new GeometryArray);
  for(IndexArray::const_iterator _it = amapSymbol->getIndexList()->begin();
  _it != amapSymbol->getIndexList()->end(); _it++){
	Point3ArrayPtr points(new Point3Array);
	for(Index::const_iterator _i = _it->begin(); _i != _it->end(); _i++){
	  points->push_back(amapSymbol->getPointList()->getAt(*_i));
	}
	points->push_back(amapSymbol->getPointList()->getAt(*(_it->begin())));
	polys->push_back(GeometryPtr(new Polyline(points)));
  }
  if(polys->empty())__wire = GeometryPtr();
  else if(polys->size() == 1)__wire = polys->getAt(0);
  else __wire = GeometryPtr(new Group(polys));
  return true;
}
bool	SOctree::recursiveBuild(RadPrimList & inPolys, const RadPatchList & inLights, sBuildInfo & bi, const unsigned int depth)
{
	// Per-node stats

	bi.totalNodes++;
	bi.totalDepth += depth;

	// User display

	if (!updateDisplay(bi, depth)) return false;

	// Conditions for being a leaf...

	bool	leaf = false;
	assert(inPolys.size() || inLights.size());
	if (depth >= bi.maxDepthLimiter) leaf = true;
	if (radius() <= bi.minRadiusLimiter) leaf = true;
	if (inPolys.size() <= bi.thresholdLimiter) leaf = true;

	// Am I a leaf?

	if (leaf)
	{
		// This _is_ a clipping octree, is it not? :)

		polys() = inPolys;
		{
			for (RadPrimList::node *i = polys().head(); i; i = i->next())
			{
				RadPrim &	p = i->data();

				// Six sides to clip to

				for (unsigned int j = 0; j < 6; ++j)
				{
					// Origin & Center of this node-bounding plane

					geom::Point3	org = center() + planeCenterOffsets[j] * radius();
					geom::Vector3	dir = -planeCenterOffsets[j];

					// Build a plane that faces the interior of the node

					geom::Plane3	plane(org, dir);

					// Clip this polygon to the plane, keeping everything in the interior of the node

					RadPrim		backSide;
					p.bisect(plane, backSide);
				}

				bi.processedSurfaceArea += p.calcArea();
			}
		}

		// Build a BSP tree from this sucker
		{
			buildInfo.scenePolys = &polys();
			buildInfo.quantizeResolution = bi.bspQuantizeResolution;
			buildInfo.leastDepthErrorBoundsPercent = bi.bspLeastDepthErrorBoundsPercent;
			//buildInfo.progressDialog = NULL;

			// Build the BSP

			if (!bsp().build(buildInfo)) return false;
			bi.totalPolys += buildInfo.totalPolys;
		}

		// Track lights

		bi.totalLights += inLights.size();

		return true;
	}

	// Determine which node(s) each polygon intersects

	for (unsigned int i = 0; i < 8; ++i)
	{
		// Child dimensions

		float		childRadius = radius() / 2.0f;
		geom::Point3	childCenter = center() + childCenterOffsets[i] * radius();
		geom::Point3	cr(childRadius, childRadius, childRadius);

		// The list of polygons that intersect this child's AABB

		RadPrimList	childPolys;
		childPolys.reserve(inPolys.size());
		{
			RadPrimList::node *	n = inPolys.head();
			while(n)
			{
				if (n->data().intersectAABB(childCenter, cr))
				{
					childPolys += n->data();
				}

				n = n->next();
			}

			// Remove the waste left over from what we originally reserved

			childPolys.compact();
		}

		// The list of lights that intersect this child's AABB

		RadPatchList	childLights;
		{
			geom::Point3	cMin = childCenter - childRadius;
			geom::Point3	cMax = childCenter + childRadius;

			for (RadPatchList::node * j = inLights.head(); j; j = j->next())
			{
				const geom::Point3 &	pos = j->data().origin();

				if (pos.x() >= cMin.x() && pos.x() <= cMax.x() &&
				    pos.y() >= cMin.y() && pos.y() <= cMax.y() &&
				    pos.z() >= cMin.z() && pos.z() <= cMax.z())
				{
					childLights += j->data();
				}
			}
		}

		// If there weren't any polys or lights, don't recurse

		if (!childPolys.size() && !childLights.size())
		{
			// No child goes here, stick in a placeholder

			children() += static_cast<SOctree *>(0);
			continue;
		}

		// Create a new child

		SOctree *	child = &bi.octreeNodeReservoir.get();
		child->center() = childCenter;
		child->radius() = childRadius;

		// Add this child to my array of children

		children() += child;

		// Recursively build this branch of the tree

		if (!child->recursiveBuild(childPolys, childLights, bi, depth + 1)) return false;
	}

	return true;
}
Example #10
0
// generate infill pattern as a vector of polygons
ClipperLib::Polygons Infill::makeInfillPattern(InfillType type, 
					       const vector<Poly> tofillpolys,
					       double infillDistance,
					       double offsetDistance,
					       double rotation) 
{
  this->type = type;
  //cerr << "have " << savedPatterns.size()<<" saved patterns " << endl;
  // look for saved pattern for this rotation
  Vector2d Min,Max;
  Min = layer->getMin();
  Max = layer->getMax();
  ClipperLib::Polygons cpolys;

  if (tofillpolys.size()==0) return cpolys;
  //omp_set_lock(&save_lock);
  //int tid = omp_get_thread_num( );
  //cerr << "thread "<<tid << " looking for pattern " << endl;
  if (type != PolyInfill) { // can't save PolyInfill
    if (savedPatterns.size()>0){
      //cerr << savedPatterns.size() << " patterns" << endl;
      while (rotation>2*M_PI) rotation -= 2*M_PI;
      while (rotation<0) rotation += 2*M_PI;
      this->angle= rotation;
      vector<uint> matches;
      for (vector<struct pattern>::iterator sIt=savedPatterns.begin();
      	   sIt != savedPatterns.end(); sIt++){
	//cerr << sIt->Min << sIt->Max <<endl;
	if (sIt->type == type &&
	    abs(sIt->distance-infillDistance) < 0.01 &&
	    abs(sIt->angle-rotation) < 0.01 )
	  {
	    //cerr << name << " found saved pattern no " << sIt-savedPatterns.begin() << " with " << sIt->cpolys.size() <<" polys"<< endl << "type "<< sIt->type << sIt->Min << sIt->Max << endl;
	    // is it too small for this layer?
	    if (sIt->Min.x > Min.x || sIt->Min.y > Min.y || 
		sIt->Max.x < Max.x || sIt->Max.y < Max.y) 
	      {
		matches.push_back(sIt-savedPatterns.begin());
		//break; // there is no other match
	      }
	    else {
	      //cerr <<"return "<<  sIt->cpolys.size()<< endl;
	      return sIt->cpolys;
	    }
	  }
      }
      sort(matches.rbegin(), matches.rend());
      for (uint i=0; i<matches.size(); i++) {
	//cerr << i << " - " ;
	savedPatterns.erase(savedPatterns.begin()+matches[i]);
      }
      //cerr << endl;
    }
  }
  //omp_unset_lock(&save_lock);
  // none found - make new:
  bool zigzag = false;
  switch (type)
    {
    case SmallZigzagInfill: // small zigzag lines
    zigzag = true;
    //case ZigzagInfill: // long zigzag lines, make lines later
    case SupportInfill: // stripes, but leave them as polygons
    case RaftInfill:    // stripes, but leave them as polygons
    case BridgeInfill:    // stripes, make them to lines later
    case ParallelInfill:  // stripes, make them to lines later
      {
	Vector2d center = (Min+Max)/2.;
	// make square that masks everything even when rotated
	Vector2d diag = Max-Min;
	double square = max(diag.x,diag.y);
	Vector2d sqdiag(square*2/3,square*2/3);
	Min=center-sqdiag;
	Max=center+sqdiag;
	//cerr << Min << "--"<<Max<< "::"<< center << endl;
	Poly poly(this->layer->getZ());
	for (double x = Min.x; x < Max.x; x += 2*infillDistance) {
	  poly.addVertex(Vector2d(x,Min.y));
	  if (zigzag){
	    for (double y = Min.y+infillDistance; y < Max.y; y += 2*infillDistance) {
	      poly.addVertex(Vector2d(x,y));
	      poly.addVertex(Vector2d(x+infillDistance,y+infillDistance));
	    }
	    for (double y = Max.y; y > Min.y; y -= 2*infillDistance) {
	      poly.addVertex(Vector2d(x+infillDistance,y+infillDistance));
	      poly.addVertex(Vector2d(x+2*infillDistance,y));
	    }
	  } else {
	    poly.addVertex(Vector2d(x+infillDistance,Min.y));
	    poly.addVertex(Vector2d(x+infillDistance,Max.y));
	    poly.addVertex(Vector2d(x+2*infillDistance,Max.y));
	  }
	}
	poly.addVertex(Vector2d(Max.x,Min.y-infillDistance));
	poly.addVertex(Vector2d(Min.x,Min.y-infillDistance));
	poly.rotate(center,rotation);
	vector<Poly> polys;
	polys.push_back(poly);
	cpolys = Clipping::getClipperPolygons(polys);
      }
      break;
    case HilbertInfill:  
      {
	Poly poly(this->layer->getZ());
	Vector2d center = (Min+Max)/2.;
	Vector2d diag = Max-Min;
	double square = MAX(Max.x,Max.y);
	if (infillDistance<=0) break;
	int level = (int)ceil(log2(2*square/infillDistance));
	if (level<0) break;
	//cerr << "level " << level;
	// start at 0,0 to get the same location for all layers
	poly.addVertex(Vector2d(0,0)); 
	hilbert(level, 0, infillDistance,  poly.vertices);
	vector<Poly> polys(1);
	polys[0] = poly;
	cpolys = Clipping::getClipperPolygons(polys);
      }
      break;
    case PolyInfill: // fill all polygons with their shrinked polys
      {
	vector< vector<Poly> > ipolys; // "shells"
	for (uint i=0;i<tofillpolys.size();i++){
	  double parea = Clipping::Area(tofillpolys[i]);
	  // make first larger to get clip overlap
	  double firstshrink=0.5*infillDistance;
	  if (parea<0) firstshrink=-0.5*infillDistance;
	  vector<Poly> shrinked = Clipping::getOffset(tofillpolys[i],firstshrink);
	  vector<Poly> shrinked2 = Clipping::getOffset(shrinked,0.5*infillDistance);
	  for (uint i=0;i<shrinked2.size();i++)
	    shrinked2[i].cleanup(0.3*infillDistance);
	  ipolys.push_back(shrinked2);
	  //ipolys.insert(ipolys.end(),shrinked.begin(),shrinked.end());
	  double area = Clipping::Area(shrinked);
	  //cerr << "shr " <<parea << " - " <<area<< " - " << " : " <<endl;
	  //int shrcount =1;
	  int lastnumpolys=0;
	  while (shrinked.size()>0){ 
	    if (area*parea<0)  break;
	    //cerr << "shr " <<parea << " - " <<area<< " - " << shrcount << " : " <<endl;
	    shrinked2 = Clipping::getOffset(shrinked,0.5*infillDistance);
	    for (uint i=0;i<shrinked2.size();i++)
	      shrinked2[i].cleanup(0.3*infillDistance);
	    ipolys.push_back(shrinked2);
	    //ipolys.insert(ipolys.end(),shrinked.begin(),shrinked.end());
	    lastnumpolys = shrinked.size();
	    shrinked = Clipping::getOffset(shrinked,-infillDistance);
	    for (uint i=0;i<shrinked.size();i++)
	      shrinked[i].cleanup(0.3*infillDistance);
	    area = Clipping::Area(shrinked);
	    //shrcount++;
	  }
	  // // remove last because they are too small
	  // ipolys.erase(ipolys.end()-lastnumpolys,ipolys.end());
	}
	vector<Poly> opolys;
	for (uint i=0;i<ipolys.size();i++){
	  opolys.insert(opolys.end(),ipolys[i].begin(),ipolys[i].end());
	}
	cpolys = Clipping::getClipperPolygons(opolys);
	//cerr << "cpolys " << cpolys.size() << endl; 
      }
      break;
    default:
      cerr << "infill type " << type << " unknown "<< endl;
    }
  // save 
  //tid = omp_get_thread_num( );
  //cerr << "thread "<<tid << " saving pattern " << endl;
  struct pattern newPattern;
  newPattern.type=type;
  newPattern.angle=rotation;
  newPattern.distance=infillDistance;
  newPattern.cpolys=cpolys;
  if (type != PolyInfill && type != ZigzagInfill) // can't save these
    {
      newPattern.Min=Min;
      newPattern.Max=Max;
      savedPatterns.push_back(newPattern);
      //cerr << "saved pattern " << endl;
    }
  return newPattern.cpolys;
}
Example #11
0
/* Function: controller
   -----------------------------------------
   usage: controller(<input-file-stream>);
   Accepts an input filestream as only argument.  Creates a vector of
   Poly(polynomial class) pointers. Also creates an iterator of the
   same type and proceeds to parse the input filestream based on
   relavent functionality. Controller will accept input of
   polynomials, as direct polynomial terms or as a mulitiple of 2 Polys.
   Controller will also act upon the appropriate polynomail with 2 commands
   show :  displays the polynomial ex. 2x^2+5x+1
   eval :  evaluates the polynomail with the supplied argument
 */
void controller (std::ifstream& input){

        std::vector<Poly*> polys(100);
        std::vector<Poly*>::iterator polyIt;


        /*set default value for each Poly* in polys to NULL  */
        for ( polyIt=polys.begin(); polyIt!=polys.end();polyIt++){
                (*polyIt)=NULL;
        }
/****************************************
 * Build the full vector of Polynomials from the file
 ***********************************************/
	try {
		std::string str;
                std::vector<std::string>data;
		while(std::getline(input, str, '\n'))	{
                        const char *cStr = str.c_str();
                        /* check for command or not */
                        if(isdigit(cStr[0])){
                                polyIt= polys.begin();
                                int polyPos=-1;
                                try{
                                        data = split(str, ' '); // splitting on whitespace 
                                        std::cout << "length of data= " << data.size()<< std::endl;
                                }catch(...){
                                        std::cout << "\nExeption thrown splitting string";
                                        std::cout<< "\nError Occured IN: "+str;
                                }
                                
                                polyPos= atoi(data[0].c_str());
                                std::string op_string = data[1];
                                std::cout<<  op_string << std::endl;
                                char oper= data[1][0];
                                int count=0,coeff=0,exp=-1;
                                Poly *add = new Poly();
                                /* Regular Polynomial building below.  
                                  
                                  
                                 */
                                if (oper==':'){
                                        for (unsigned i =2; i < data.size(); i++){
                                                if (count==0){
                                                        coeff= atoi(data[i].c_str());
                                                } else if( count==1){
                                                        exp=  atoi(data[i].c_str());
                                                }
                                                std::cout << "coeff =" << coeff << "expo= " << exp << std::endl;
                                                count++;
                                                if (count>=2){
                                                        add->push_term(coeff,exp);
                                                        count=0;
                                                }
                                        }
                                }

                                /* Multiplication for 2 polynomials Below.   */
                                else if (oper=='='){
                                        int poly1= atoi(data[2].c_str());
                                        int poly2= atoi(data[4].c_str());
                                        if (polys[poly1]==NULL || polys[poly2]==NULL)
                                                throw "ERROR: INVALID POLY VECTOR INDEX";
                                        add = ((*(polys[poly1]))) * (*(polys[poly2]));
                                        polys[polyPos]=add;
                                }
                                /*USE INDEX TO PLACE POLY INTO POSITION */
                                polys[polyPos]=add;
                               
                        } else {
                                /* Command Section: Split strings then execute operations
                                   based on 2 possibilities:
                                   show and eval 

                                 */

                                try{
                                        data = split(str, ' '); // splitting on whitespace 
                                }catch(...){
                                        std::cout << "\nExeption thrown splitting string";
                                        std::cout << "\nError Occured IN: "+str;
                                }
                                /*variables for switching behavior */
                                std::string command= data[0];
                                /*   */
                                enum com_Choice{show, eval} commands;
                                int operand= atoi(data[1].c_str());
                                int value= atoi(data[2].c_str());
                              
                                                             
                                if (command == "eval"){
                                        commands = eval;      
                                }else
                                        commands = show;
                                
                                switch (commands ) {
                                   
                                case show:
                                         std::cout << "Poly["<<operand<<"]="
                                                   << (*polys[operand])<<std::endl;
                                        break;
                                case eval:
                                        
                                        int result= (*polys[operand])(value );
                                        std::cout << "Poly["<<operand<<"]("<<value<<")="
                                                  <<result<< std::endl;
                                        break;
                                
                                }
                        }
                        
                        data.clear();
                        str.clear();
			
                }
        } catch(...){
		std::cout << "\nError Parsing input File:\n " << std::endl;
	}
        
}