void QgsTessellatedPolygonGeometry::setPolygons( const QList<QgsPolygon *> &polygons, const QList<QgsFeatureId> &featureIds, const QgsPointXY &origin, float extrusionHeight, const QList<float> &extrusionHeightPerPolygon )
{
  Q_ASSERT( polygons.count() == featureIds.count() );
  mTriangleIndexStartingIndices.reserve( polygons.count() );
  mTriangleIndexFids.reserve( polygons.count() );

  QgsTessellator tessellator( origin.x(), origin.y(), mWithNormals, mInvertNormals, mAddBackFaces );
  for ( int i = 0; i < polygons.count(); ++i )
  {
    Q_ASSERT( tessellator.dataVerticesCount() % 3 == 0 );
    uint startingTriangleIndex = static_cast<uint>( tessellator.dataVerticesCount() / 3 );
    mTriangleIndexStartingIndices.append( startingTriangleIndex );
    mTriangleIndexFids.append( featureIds[i] );

    QgsPolygon *polygon = polygons.at( i );
    float extr = extrusionHeightPerPolygon.isEmpty() ? extrusionHeight : extrusionHeightPerPolygon.at( i );
    tessellator.addPolygon( *polygon, extr );
  }

  qDeleteAll( polygons );

  QByteArray data( ( const char * )tessellator.data().constData(), tessellator.data().count() * sizeof( float ) );
  int nVerts = data.count() / tessellator.stride();

  mVertexBuffer->setData( data );
  mPositionAttribute->setCount( nVerts );
  if ( mNormalAttribute )
    mNormalAttribute->setCount( nVerts );
}
Exemplo n.º 2
0
void QgsTessellatedPolygonGeometry::setPolygons( const QList<QgsPolygon *> &polygons, const QgsPointXY &origin, float extrusionHeight, const QList<float> &extrusionHeightPerPolygon )
{
  QgsTessellator tessellator( origin.x(), origin.y(), mWithNormals, mInvertNormals );
  for ( int i = 0; i < polygons.count(); ++i )
  {
    QgsPolygon *polygon = polygons.at( i );
    float extr = extrusionHeightPerPolygon.isEmpty() ? extrusionHeight : extrusionHeightPerPolygon.at( i );
    tessellator.addPolygon( *polygon, extr );
  }

  qDeleteAll( polygons );

  QByteArray data( ( const char * )tessellator.data().constData(), tessellator.data().count() * sizeof( float ) );
  int nVerts = data.count() / tessellator.stride();

  mVertexBuffer->setData( data );
  mPositionAttribute->setCount( nVerts );
  if ( mNormalAttribute )
    mNormalAttribute->setCount( nVerts );
}
Exemplo n.º 3
0
//Load TSM file
GLC_World GLWidget::loadTSMFile( const QString &filename )
{
	RhBuilderPtr reader = makePtr<RhBuilder>(filename.toStdString());
	TSplinePtr spline = reader->findTSpline();

	GLC_World w;

	IndexList face;
	QList<float> vertex;
	QList<float> normal;

	TTessellator tessellator(spline);

	TImagePtr image = spline->getTImage();

	// Go through all the faces in TImage and create abjects 
	TFacVIterator fiter = image->faceIteratorBegin();
	for (;fiter!=image->faceIteratorEnd();fiter++)
	{
		TFacePtr tface = *fiter;

		TriMeshPtr trimesh = tessellator.interpolateFace(tface);

		P3dVIterator piter = trimesh->pointIteratorBegin();
		for (piter;piter!=trimesh->pointIteratorEnd();piter++)
		{
			vertex.push_back((*piter)->x());
			vertex.push_back((*piter)->y());
			vertex.push_back((*piter)->z());
		}

		N3dVIterator niter = trimesh->normalIteratorBegin();
		for (;niter!=trimesh->normalIteratorEnd();niter++)
		{
			normal.push_back((*niter)->i());
			normal.push_back((*niter)->j());
			normal.push_back((*niter)->k());
		}

		TriVIterator titer = trimesh->triangleIteratorBegin();
		for (;titer!=trimesh->triangleIteratorEnd();titer++)
		{
			face.push_back((*titer)->point_indices[0]);
			face.push_back((*titer)->point_indices[1]);
			face.push_back((*titer)->point_indices[2]);
		}

		GLC_Mesh* glc_mesh = new GLC_Mesh();
		glc_mesh->addTriangles(0,face);
		face.clear();
		glc_mesh->addVertice(vertex.toVector());
		vertex.clear();
		glc_mesh->addNormals(normal.toVector());
		normal.clear();
		glc_mesh->finish();

		GLC_3DRep *rep = new GLC_3DRep(glc_mesh);
		glc_mesh = NULL;
		
		// Set the material 
		GLC_Material* pCurrentMat= NULL;
		pCurrentMat= rep->geomAt(0)->firstMaterial();
		pCurrentMat->setAmbientColor(Qt::gray);
		pCurrentMat->setDiffuseColor(Qt::gray);

		// Add objects (faces) to the world collection 
		w.collection()->add(*rep);
	}
	return w;
}