Пример #1
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;
}
Пример #2
0
bool WireComputer::process( Polyline2D * polyline ){
  GEOM_ASSERT( polyline );

  GEOM_WireComputer_CHECK_CACHE( polyline );
  Point3ArrayPtr a (new Point3Array(*(polyline->getPointList()),0));
  __wire = GeometryPtr(new Polyline(a));
  GEOM_WireComputer_UPDATE_CACHE(polyline);
  return true;
}
Пример #3
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;
}
Пример #4
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;
}
Пример #5
0
GeometryPtr parseGeometry(TiXmlElement *g)
{
  GeometryPtr geom;
  if (!g) return geom;

  TiXmlElement *shape = g->FirstChildElement();
  if (!shape)
  {
    logError("Geometry tag contains no child element.");
    return geom;
  }

  std::string type_name = shape->ValueStr();
  if (type_name == "sphere")
  {
    Sphere *s = new Sphere();
    resetPtr(geom,s);
    if (parseSphere(*s, shape))
      return geom;
  }
  else if (type_name == "box")
  {
    Box *b = new Box();
    resetPtr(geom,b);
    if (parseBox(*b, shape))
      return geom;
  }
  else if (type_name == "cylinder")
  {
    Cylinder *c = new Cylinder();
    resetPtr(geom,c);
    if (parseCylinder(*c, shape))
      return geom;
  }
  else if (type_name == "mesh")
  {
    Mesh *m = new Mesh();
    resetPtr(geom,m);
    if (parseMesh(*m, shape))
      return geom;
  }
  else
  {
    logError("Unknown geometry type '%s'", type_name.c_str());
    return geom;
  }

  return GeometryPtr();
}
Пример #6
0
GeometryPtr 
Overlay::process(const Polyline2DPtr& p1, const Polyline2DPtr& p2)
{
	if (!p1 || !p2 || p1->getPointListSize() < 2 || p2->getPointListSize() < 2) return GeometryPtr();
#ifdef WITH_CGAL

  // Construct the first arrangement, containing a polyline 1.
  Arrangement_2          arr1;

  for (Point2Array::const_iterator it1 = p1->getPointList()->begin()+1; it1 != p1->getPointList()->end(); ++it1)
	insert_non_intersecting_curve(arr1,toSegment(*(it1-1),*it1));

  // to be a closed face, first and last point should be exactly the same.
  // However we should not duplicate the same point twice at the end.
  Vector2& fp1 = p1->getPointList()->getAt(0);
  Vector2& lp1 = *(p1->getPointList()->end()-1);
  if (fp1.x() != lp1.x() || fp1.y() != lp1.y())
	insert_non_intersecting_curve(arr1,toSegment(lp1,fp1));

  // std::cerr << arr1.number_of_vertices() << " " << arr1.number_of_edges() << " " << arr1.number_of_faces() << std::endl;

  // Mark just the bounded face.
  Arrangement_2::Face_iterator   fit;

  CGAL_assertion (arr1.number_of_faces() == 2);
  for (fit = arr1.faces_begin(); fit != arr1.faces_end(); ++fit)
    fit->set_data (fit != arr1.unbounded_face());

  // Construct the second arrangement.
  Arrangement_2          arr2;

  for (Point2Array::const_iterator it2 = p2->getPointList()->begin()+1; it2 != p2->getPointList()->end(); ++it2)
	 	insert(arr2,toSegment(*(it2-1),*it2));

  // to be a closed face, first and last point should be exactly the same.
  // However we should not duplicate the same point twice at the end.
  Vector2& fp2 = p2->getPointList()->getAt(0);
  Vector2& lp2 = *(p2->getPointList()->end()-1);
  if (fp2.x() != lp2.x() || fp2.y() != lp2.y())
	insert(arr2,toSegment(lp2,fp2)); 

  // std::cerr << arr2.number_of_vertices() << " " << arr2.number_of_edges() << " " << arr2.number_of_faces() << std::endl;

  CGAL_assertion (arr2.number_of_faces() == 2);
  for (fit = arr2.faces_begin(); fit != arr2.faces_end(); ++fit)
    fit->set_data (fit != arr2.unbounded_face());

  // Compute the overlay of the two arrangements.
  Arrangement_2          overlay_arr;
  Overlay_traits         overlay_traits;

  overlay (arr1, arr2, overlay_arr, overlay_traits);

  // std::cerr << overlay_arr.number_of_vertices() << " " << overlay_arr.number_of_edges() << " " << overlay_arr.number_of_faces() << std::endl;

  // conversion between cgal structures and plantgl ones.
  GeometryArrayPtr geomarray(new GeometryArray(0));
  for (Arrangement_2::Face_iterator face = overlay_arr.faces_begin(); face != overlay_arr.faces_end(); ++face)
  {
    if (face->is_fictitious () || face->is_unbounded())
		continue;
    if (! face->data())
      continue;
   
    Arrangement_2::Ccb_halfedge_circulator curr = face->outer_ccb();
	Point2ArrayPtr pointSet( new Point2Array(1,toVec2(curr->source()->point())));
    do
    {
	  pointSet->push_back(toVec2(curr->target()->point()));
      ++curr;
    } while (curr != face->outer_ccb());
	if (pointSet->size() == 1){
		geomarray->push_back(GeometryPtr(new PointSet2D(pointSet)));
	}
	else if(pointSet->size() > 1){
		geomarray->push_back(GeometryPtr(new Polyline2D(pointSet)));
	}
  }
  if (geomarray->empty())return GeometryPtr();
  else if (geomarray->size() == 1) return geomarray->getAt(0);
  else return GeometryPtr(new Group(geomarray));

#else
#ifdef _MSC_VER
#pragma message("CGAL not included. Overlay routine will not work.")
#else
#warning "CGAL not included. Overlay routine will not work."
#endif
	pglError("CGAL not included. Overlay routine will not work.");
	return GeometryPtr();
#endif

}
Пример #7
0
bool WireComputer::process( Font * font ){
  GEOM_ASSERT(font);
  __wire = GeometryPtr();
  return true;
}
Пример #8
0
bool WireComputer::process( Text * text ){
  GEOM_ASSERT(text);
  __wire = GeometryPtr();
  return true;
}
Пример #9
0
bool WireComputer::process( PointSet2D * pointSet ){
  GEOM_ASSERT(pointSet);

  __wire = GeometryPtr();
  return true;
}
Пример #10
0
/* ----------------------------------------------------------------------- */
bool WireComputer::process( Material * material ) {
  GEOM_ASSERT(material);
  // nothing to do
  __wire = GeometryPtr();
  return false;
}
Пример #11
0
bool WireComputer::process( Polyline * polyline ) {
  GEOM_ASSERT(polyline);
  // nothing to do as quadSet is already an ExplicitModel
  __wire = GeometryPtr(polyline);
  return true;
}
Пример #12
0
bool WireComputer::process( MultiSpectral * multiSpectral ) {
  GEOM_ASSERT(multiSpectral);
  // nothing to do
  __wire = GeometryPtr();
  return false;
}
Пример #13
0
bool WireComputer::process( Texture2DTransformation * texture ) {
  GEOM_ASSERT(texture);
  // nothing to do
  __wire = GeometryPtr();
  return false;
}
Пример #14
0
bool WireComputer::process( ImageTexture * texture ) {
  GEOM_ASSERT(texture);
  // nothing to do
  __wire = GeometryPtr();
  return false;
}
Пример #15
0
void TextSprite::createGeometry()
{
	Model::GroupMap &groups = getGroups();
	GeometryPtr &g = groups[bRenderer::DEFAULT_GROUP_NAME()];
	if (!g)
		g = GeometryPtr(new Geometry);

	GeometryDataPtr gData = GeometryDataPtr(new GeometryData);

	GLuint verNum = 6;
	GLuint fontPixelSize = _font->getPixelSize();
	// Initialize position of the first sprite
	GLfloat pos_x = 0.f;
	GLfloat pos_y = 0.f;
	GLfloat z = 0.f;
	bool beginningofLine = true;

	// Create a sprite per character
	for (GLuint i = 0; i < _text.length(); i++){
		if (_text.at(i) == '\n')
		{
			beginningofLine = true;
			pos_x = 0.f;
			pos_y -= 1.0f;
			// The line break has to be erased instead of just increasing i
			// otherwise the indices wouldn't be correct anymore
			_text.erase(_text.begin() + i);
			// If the line break was at the end of the string we have to leave the loop
			if (i >= _text.length())
				break;
		}

		// load character
		ftgl::texture_glyph_t* glyph = _font->getCharacter(_text.at(i));

		if (glyph != NULL)
		{

			GLfloat u0 = glyph->s0;
			GLfloat v0 = glyph->t0;
			GLfloat u1 = glyph->s1;
			GLfloat v1 = glyph->t1;

			GLfloat x0 = pos_x + (beginningofLine ? 0.f : (static_cast<GLfloat>(glyph->offset_x) / fontPixelSize));
			GLfloat y0 = pos_y + (static_cast<GLfloat>(glyph->offset_y) / fontPixelSize);
			GLfloat x1 = x0 + (static_cast<GLfloat>(glyph->width) / fontPixelSize);
			GLfloat y1 = y0 - (static_cast<GLfloat>(glyph->height) / fontPixelSize);

			pos_x += static_cast<GLfloat>(glyph->advance_x) / fontPixelSize;
			pos_y += static_cast<GLfloat>(glyph->advance_y) / fontPixelSize;

			beginningofLine = false;

			// Add vertices
			gData->vboVertices.push_back(Vertex(
				x0, y0, z,					// position
				0.0f, 0.0f, -1.0f,			// normal
				-1.0f, 0.0f, 0.0f,			// tangent
				0.0f, 1.0f, 0.0f,			// bitangent
				u0, v0						// texCoord
			));
			gData->vboVertices.push_back(Vertex(
				x1, y1, z,					// position
				0.0f, 0.0f, -1.0f,			// normal
				-1.0f, 0.0f, 0.0f,			// tangent
				0.0f, 1.0f, 0.0f,			// bitangent
				u1, v1						// texCoord
				));
			gData->vboVertices.push_back(Vertex(
				x1, y0, z,					// position
				0.0f, 0.0f, -1.0f,			// normal
				-1.0f, 0.0f, 0.0f,			// tangent
				0.0f, 1.0f, 0.0f,			// bitangent
				u1, v0						// texCoord
				));
			gData->vboVertices.push_back(Vertex(
				x0, y0, z,					// position
				0.0f, 0.0f, -1.0f,			// normal
				-1.0f, 0.0f, 0.0f,			// tangent
				0.0f, 1.0f, 0.0f,			// bitangent
				u0, v0						// texCoord
				));
			gData->vboVertices.push_back(Vertex(
				x0, y1, z, 					// position
				0.0f, 0.0f, -1.0f,			// normal
				-1.0f, 0.0f, 0.0f,			// tangent
				0.0f, 1.0f, 0.0f,			// bitangent
				u0, v1						// texCoord
				));
			gData->vboVertices.push_back(Vertex(
				x1, y1, z,					// position
				0.0f, 0.0f, -1.0f,			// normal
				-1.0f, 0.0f, 0.0f,			// tangent
				0.0f, 1.0f, 0.0f,			// bitangent
				u1, v1						// texCoord	
				));

			// Add indices
			for (GLushort j = (0 + i*verNum); j < (6 + i*verNum); j++)
				gData->vboIndices.push_back(j);

			// Add index data
			gData->indices.push_back(IndexData(3 + i*verNum, 2 + i*verNum, 0 + i*verNum));
			gData->indices.push_back(IndexData(2 + i*verNum, 1 + i*verNum, 0 + i*verNum));
			gData->indices.push_back(IndexData(0 + i*verNum, 0 + i*verNum, 0 + i*verNum));
			gData->indices.push_back(IndexData(1 + i*verNum, 5 + i*verNum, 0 + i*verNum));
			gData->indices.push_back(IndexData(3 + i*verNum, 4 + i*verNum, 0 + i*verNum));
			gData->indices.push_back(IndexData(0 + i*verNum, 3 + i*verNum, 0 + i*verNum));
		}
	}

	g->initialize(gData);

	setBoundingBoxObjectSpace(g->getBoundingBoxObjectSpace());
}
Пример #16
0
const GeometryPtr 
Deformed::getGeometry( ) const {
  return GeometryPtr(__primitive);
}
Пример #17
0
void WireComputer::clear( ) {
  __wire = GeometryPtr();
  __cache.clear();
}