Exemplo n.º 1
0
// adds an arc to the given center, start point, pen width, and angle (degrees).
bool VRML_LAYER::AppendArc( double aCenterX, double aCenterY, double aRadius,
                            double aStartAngle, double aAngle, int aContourID )
{
    if( aContourID < 0 || (unsigned int) aContourID >= contours.size() )
    {
        error = "AppendArc(): invalid contour (out of range)";
        return false;
    }

    aAngle = aAngle / 180.0 * M_PI;
    aStartAngle = aStartAngle / 180.0 * M_PI;

    int nsides = calcNSides( aRadius, aAngle );

    double da = aAngle / nsides;

    bool fail = false;

    if( aAngle > 0 )
    {
        aAngle += aStartAngle;
        for( double ang = aStartAngle; ang < aAngle; ang += da )
            fail |= !AddVertex( aContourID, aCenterX + aRadius * cos( ang ),
                                aCenterY + aRadius * sin( ang ) );
    }
    else
    {
        aAngle += aStartAngle;
        for( double ang = aStartAngle; ang > aAngle; ang += da )
            fail |= !AddVertex( aContourID, aCenterX + aRadius * cos( ang ),
                                aCenterY + aRadius * sin( ang ) );
    }

    return !fail;
}
Exemplo n.º 2
0
bool add(int which_poly, int x, int y) 
{ 
    bool res = false;
    vertex *v; 

    v = (vertex*)malloc(sizeof(vertex)); 
    v->x = x; 
    v->y = y;
    v->alpha = 0.;
    v->internal = false;
    v->linkTag = 0;

    if (which_poly == 1) 
    { 
	v->next = s_size+1 ;
	res = AddVertex(s,s_size,v);
    } 
    else if (which_poly == 2) 
    { 
	v->next = c_size+1 ;
	res = AddVertex(c,c_size,v);
    } 
    else {
	printf("%d is not a valid polygon index.\n",which_poly);
	exit(1);
    }
    free(v);

    return res;
}
Exemplo n.º 3
0
Mesh::Mesh(Program &program)
	: Drawable(program)
	, vbuffer(-1)
	, nbuffer(-1)
	, tbuffer(-1)
	, fbuffer(-1)
	, texture(NULL)
{
	AddVertex(-1.0, -1.0, -1.0);
	AddVertex(-1.0, 1.0, -1.0);
	AddVertex(1.0, 1.0, -1.0);
	AddVertex(1.0, -1.0, -1.0);

	AddTexcoord(0, 1);
	AddTexcoord(0, 0);
	AddTexcoord(1, 0);
	AddTexcoord(1, 1);

	AddColour(1.0, 0.0, 0.0);
	AddColour(0.0, 1.0, 0.0);
	AddColour(0.0, 0.0, 1.0);
	AddColour(1.0, 1.0, 1.0);

	AddNormal(0.0, 0.0, 1.0);
	AddNormal(0.0, 0.0, 1.0);
	AddNormal(0.0, 0.0, 1.0);
	AddNormal(0.0, 0.0, 1.0);

	AddFace(0, 1, 2);
	AddFace(2, 3, 0);
	InitBuffers();
}
	void CDX9Renderer::Box(const rect& r, cr_float angle, point hotspot, const color& c)
	{
		// No support for textured lines
		SetTexture(NULL);

		quad q((r - hotspot).rotate_to_quad(angle, r.topleft()));

		BeginBatch(batch_linestrip);
		CBatch_Draw* draw_op = reinterpret_cast<CBatch_Draw*>(batch.back());

		D3DCOLOR color = c.getD3DCOLOR();

		// 4 vertices and use 5th index to repeat first vertex closing the strip as a box
		AddVertex(color, q.tl, 0.0f, 0.0f);
		AddVertex(color, q.tr, 0.0f, 0.0f);
		AddVertex(color, q.br, 0.0f, 0.0f);
		AddVertex(color, q.bl, 0.0f, 0.0f);

		unsigned short index = draw_op->vertex_count;
		AddIndex(index);
		AddIndex(index + 1);
		AddIndex(index + 2);
		AddIndex(index + 3);
		AddIndex(index);

		draw_op->vertex_count += 4;
		draw_op->index_count += 5;
	}
Exemplo n.º 5
0
void Mesh::ReadVertexData(FILE *fp, int num, bool have_normals, bool have_tex)
{
	double n[3];
	double v[3];
	double t[2];
	char buf[1024];
	for(int i = 0; i < num; i++)
	{
		fgets(buf, 1024, fp);
		if(have_normals && have_tex)
		{
			sscanf(buf, "%lf %lf %lf %lf %lf %lf %lf %lf", v, v+1, v+2, n, n+1, n+2, t, t+1);
			AddVertex(v);
			AddNormal(n);
			AddTexcoord(t);
		}
		else if(have_normals)
		{
			sscanf(buf, "%lf %lf %lf %lf %lf %lf", v, v+1, v+2, n, n+1, n+2);
			AddVertex(v);
			AddNormal(n);
		}
		else if(have_tex)
		{
			sscanf(buf, "%lf %lf %lf %lf %lf", v, v+1, v+2, t, t+1);
			AddVertex(v);
			AddTexcoord(t);
		}
		else
		{
			sscanf(buf, "%lf %lf %lf", v, v+1, v+2);
			AddVertex(v);
		}
	}
}
	void CDX9Renderer::Box(const rect& r, const color& c)
	{
		// No support for textured lines
		SetTexture(NULL);

		BeginBatch(batch_linestrip);
		CBatch_Draw* draw_op = reinterpret_cast<CBatch_Draw*>(batch.back());

		D3DCOLOR color = c.getD3DCOLOR();

		// 4 vertices and use 5th index to repeat first vertex closing the strip as a box
		AddVertex(color, r.topleft(), 0.0f, 0.0f);
		AddVertex(color, r.topright(), 0.0f, 0.0f);
		AddVertex(color, r.bottomright(), 0.0f, 0.0f);
		AddVertex(color, r.bottomleft(), 0.0f, 0.0f);

		unsigned short index = draw_op->vertex_count;
		AddIndex(index);
		AddIndex(index + 1);
		AddIndex(index + 2);
		AddIndex(index + 3);
		AddIndex(index);

		draw_op->vertex_count += 4;
		draw_op->index_count += 5;
	}
Exemplo n.º 7
0
void CircleEvaluator::Evaluate() {
    // Add the vertexes specified
    double x;
    double y;
    double pi = 3.14159265;

    // We parametrically evaluate the circle
    // x = sin(t)
    // y = cos(t)
    // t goes from 0 to 2pi
    // 0 degrees = 0rad, 90 degrees = pi/2rad, etc.

    double startRad = m_StartArcDegrees / 180 * pi;
    double endRad = m_EndArcDegrees / 180 * pi;
    double radPerPoint = m_DegreesPerPoint / 180 * pi;

    if (startRad > endRad)
        endRad += 2*pi;

    double currentRad = startRad;

    do {
        x = m_Radius*sin(currentRad) + m_XOrigin;
        y = m_Radius*cos(currentRad) + m_YOrigin;

        AddVertex(x,y);
        currentRad += radPerPoint;
    } while (currentRad < endRad);

    x = m_Radius*sin(endRad) + m_XOrigin;
    y = m_Radius*cos(endRad) + m_YOrigin;

    AddVertex(x, y);
}
bool CFuzzyMembershipFunction::InitTriangle (long x1, long x2, long x3)
{
  if ((x1 < x2) && (x2 < x3))
  {
    CFuzzyElement FE;
    DeleteVertices();

    // Left vertex.
    FE.SetValue(x1);
    FE.SetMembership(0.0);
    AddVertex(FE);

    // Peak vertex.
    FE.SetValue(x2);
    FE.SetMembership(1.0);
    AddVertex(FE);

    // Right vertex.
    FE.SetValue(x3);
    FE.SetMembership(0.0);
    AddVertex(FE);

    return true;
  }

  return false;
}
Exemplo n.º 9
0
/**
 * @function BuildManifold
 */
void HP2D::BuildManifold( Vertex* _v0 ) {
	
	Vertex* va;
    std::vector<Vertex*> S;
	std::vector<Vertex*> B;

	printf("Build Manifold \n");
	AddVertex( _v0 );	
	EnQueue( _v0 );

	while( mQ.size() != 0 ) {
		va = DeQueue();
		S = Successors( va );

		for( unsigned int i = 0; i < S.size(); ++i ) {
			AddVertex( S[i] );
			AddEdge( va, S[i] );
			if( S[i]->GetDist() < DIST_MAX ) {		
				EnQueue( S[i] );
			}
			B = GetAdjacent2( va );
			for( unsigned j = 0; j < B.size(); ++j ) {
				if( CheckPosNeighbors( B[j], S[i] ) == true ) {
					AddEdge( S[i], B[j] );
				}
			}
		}		
	}
}
Exemplo n.º 10
0
    /** Add triangle to connectivity information */
    int32 AddTriangle( const FVector &a, const FVector &b, const FVector &c )
    {
        // Map vertices
        int32 VertexA = AddVertex( a );
        int32 VertexB = AddVertex( b );
        int32 VertexC = AddVertex( c );

        // Make sure triangle is not degenerated
        if ( VertexA!=VertexB && VertexB!=VertexC && VertexC!=VertexA )
        {
            // Setup connectivity info
            int32 TriangleIndex = Triangles.Num();
            Vertices[ VertexA ].AddTriangleLink( TriangleIndex );
            Vertices[ VertexB ].AddTriangleLink( TriangleIndex );
            Vertices[ VertexC ].AddTriangleLink( TriangleIndex );

            // Create triangle
            new ( Triangles ) FMeshConnectivityTriangle( VertexA, VertexB, VertexC );
            return TriangleIndex;
        }
        else
        {
            // Degenerated triangle
            return INDEX_NONE;
        }
    }
Exemplo n.º 11
0
// adds a circle the existing list; if 'hole' is true the contour is
// a hole. Returns true if OK.
bool VRML_LAYER::AddCircle( double x, double y, double rad, int csides, bool hole )
{
    int pad = NewContour();

    if( pad < 0 )
    {
        error = "AddCircle(): failed to add a contour";
        return false;
    }

    if( csides < 6 )
        csides = CalcNSides( rad, maxdev );

    // even numbers give prettier results
    if( csides & 1 )
        csides += 1;

    double da = M_PI * 2.0 / csides;

    bool fail = false;

    if( hole )
    {
        for( double angle = 0; angle < M_PI * 2; angle += da )
            fail |= !AddVertex( pad, x + rad * cos( angle ), y - rad * sin( angle ) );
    }
    else
    {
        for( double angle = 0; angle < M_PI * 2; angle += da )
            fail |= !AddVertex( pad, x + rad * cos( angle ), y + rad * sin( angle ) );
    }

    return !fail;
}
bool CFuzzyMembershipFunction::InitTrapezoid (long x1, long x2, long x3, long x4)
{
  if ((x1 < x2) && (x2 < x3) && (x3 < x4))
  {
    CFuzzyElement FE;
    DeleteVertices();

    // Leftmost vertex.
    FE.SetValue(x1);
    FE.SetMembership(0.0);
    AddVertex(FE);

    // Left peak vertex.
    FE.SetValue(x2);
    FE.SetMembership(1.0);
    AddVertex(FE);

    // Right peak vertex.
    FE.SetValue(x3);
    FE.SetMembership(1.0);
    AddVertex(FE);

    // Rightmost vertex.
    FE.SetValue(x4);
    FE.SetMembership(0.0);
    AddVertex(FE);

    return true;
  }

  return false;
}
Exemplo n.º 13
0
int AdjList::AddEdge(const Vertex& from, const Vertex& to, int cost)
{

	if(!hasVertex(from))
	{
		AddVertex(from);
	}
	
	if(!hasVertex(to))
	{
		AddVertex(to);
	}
	
	for(auto& vinfo: m_vinfoList)
	{
		if(from == vinfo.m_vertex)
		{
			for(const auto& edge: vinfo.m_edges)
			{
				if(edge.m_to == to)
				{
					return -1; // already added
				}
			}
			vinfo.m_edges.push_back({to, cost});
			return GRAPH_OK;
		}
	}

	return GRAPH_ERROR_VERTEX_NOT_FOUND;
}
bool CFuzzyMembershipFunction::InitTrapezoid (const CFuzzyElement& v1, const CFuzzyElement& v2, const CFuzzyElement& v3, const CFuzzyElement v4)
{
  if ((v1.GetValue() < v2.GetValue()) && (v2.GetValue() < v3.GetValue()) && (v3.GetValue() < v4.GetValue()) &&
      (v2.GetMembership() > v1.GetMembership()) && (v2.GetMembership() > v4.GetMembership()) && 
      (v3.GetMembership() > v1.GetMembership()) && (v3.GetMembership() > v4.GetMembership()))
  {
    DeleteVertices();

    // Leftmost vertex.
    AddVertex(v1);
    
    // Left peak vertex.
    AddVertex(v2);

    // Right peak vertex.
    AddVertex(v3);

    // Rightmost vertex.
    AddVertex(v4);

    return true;
  }

  return false;
}
Exemplo n.º 15
0
void Scene::Extrude (int n, float* x, float* y, float depth, 
		     const Trafo& P, const ColorB* color)
{
  int n1 = n-1, n2 = 2*n-2;
     
  // add front and back polygonal with n vertices
  // the back polygonal has reverse orientation

  Facet &front = AddFacet(n),
        &back  = AddFacet(n);
    
  if (color) {
    front.SetColor(*color);
    back.SetColor(*color);
  }

  // create vertices and link them to facets
  int i;
  for (i = 0; i < n; i++) { 
    front(i) = &AddVertex( P * Vertex(x[i],y[i],0.0) );
    back(i)  = &AddVertex( P * Vertex(x[n1-i],y[n1-i],-depth) );
    if (color) {
      front[i].SetColor(*color);
      back[i].SetColor(*color);
    }
  }

  // create n facets for the sides and link the vertices
  for (i = 0; i < n; i++) { 
    Facet &side = AddFacet(4, front(i), back(n1-i),
			   back((n2-i)%n), front((i+1)%n) );
    if (color) side.SetColor(*color);
  }
}
Exemplo n.º 16
0
void kexCpuVertList::AddLine(float x1, float y1, float z1,
                          float x2, float y2, float z2,
                          byte r, byte g, byte b, byte a) {
    
    *(roverIndices++) = vertexCount; indiceCount++;
    AddVertex(x1, y1, z1, 0, 0, r, g, b, a);
    *(roverIndices++) = vertexCount; indiceCount++;
    AddVertex(x2, y2, z2, 0, 0, r, g, b, a);
}
Exemplo n.º 17
0
void CSimpleUGraph< ObjT, Compare >::AddEdge( const ObjT &oV1, const ObjT & oV2 )
{
  typename boost::graph_traits<Graph>::edge_descriptor e;
  bool bAdded;
  AddVertex( oV1 );   // should lazy these two - check to see if vertex is there first
  AddVertex( oV2 );
  Vertex u = oDataToVertexMap[ oV1 ];
  Vertex v = oDataToVertexMap[ oV2 ];
  boost::tie( e, bAdded ) = add_edge( v, u, oBoostGraph );    // add edge
}
Exemplo n.º 18
0
void kexCpuVertList::AddLine(float x1, float y1, float z1,
                          float x2, float y2, float z2,
                          byte r1, byte g1, byte b1, byte a1,
                          byte r2, byte g2, byte b2, byte a2) {
    
    *(roverIndices++) = vertexCount; indiceCount++;
    AddVertex(x1, y1, z1, 0, 0, r1, g1, b1, a1);
    *(roverIndices++) = vertexCount; indiceCount++;
    AddVertex(x2, y2, z2, 0, 0, r2, g2, b2, a2);
}
Exemplo n.º 19
0
/// <summary>
/// Helper function to create a face for the base octahedron.
/// </summary>
/// <param name="mesh">Mesh</param>
/// <param name="p1">Vertex 1.</param>
/// <param name="p2">Vertex 2.</param>
/// <param name="p3">Vertex 3.</param>
void AddBaseTriangle(D3DVECTOR& p1, D3DVECTOR& p2, D3DVECTOR& p3)
{
    AddVertex(p1.x, p1.y, p1.z, p1.x, p1.y, p1.z, 0, 0);
    AddVertex(p2.x, p2.y, p2.z, p2.x, p2.y, p2.z, 0, 0);
    AddVertex(p3.x, p3.y, p3.z, p3.x, p3.y, p3.z, 0, 0);
    
    AddIndex(nextIndex++);
    AddIndex(nextIndex++);
    AddIndex(nextIndex++);
}
Exemplo n.º 20
0
bool VRML_LAYER::AppendCircle( double aXpos, double aYpos,
                               double aRadius, int aContourID,
                               bool aHoleFlag )
{
    if( aContourID < 0 || (unsigned int) aContourID >= contours.size() )
    {
        error = "AppendCircle(): invalid contour (out of range)";
        return false;
    }

    int nsides = M_PI * 2.0 * aRadius / minSegLength;

    if( nsides > maxArcSeg )
    {
        if( nsides > 2 * maxArcSeg )
        {
            // use segments approx. maxAr
            nsides = M_PI * 2.0 * aRadius / maxSegLength;
        }
        else
        {
            nsides /= 2;
        }
    }

    if( nsides < MIN_NSIDES )
        nsides = MIN_NSIDES;

    // even numbers give prettier results for circles
    if( nsides & 1 )
        nsides += 1;

    double da = M_PI * 2.0 / nsides;

    bool fail = false;

    if( aHoleFlag )
    {
        fail |= !AddVertex( aContourID, aXpos + aRadius, aYpos );

        for( double angle = da; angle < M_PI * 2; angle += da )
            fail |= !AddVertex( aContourID, aXpos + aRadius * cos( angle ),
                                aYpos - aRadius * sin( angle ) );
    }
    else
    {
        fail |= !AddVertex( aContourID, aXpos + aRadius, aYpos );

        for( double angle = da; angle < M_PI * 2; angle += da )
            fail |= !AddVertex( aContourID, aXpos + aRadius * cos( angle ),
                                aYpos + aRadius * sin( angle ) );
    }

    return !fail;
}
Exemplo n.º 21
0
/* Read network from the training file */
void ReadData()
{
  FILE *fin;
  char name_v1[MAX_STRING], name_v2[MAX_STRING], str[2 * MAX_STRING + 10000];
  int vid;
  double weight;

  fin = fopen(network_file, "rb");
  if (fin == NULL)
  {
    printf("ERROR: network file not found!\n");
    exit(1);
  }
  num_edges = 0;
  while (fgets(str, sizeof(str), fin)) num_edges++;
  fclose(fin);
  printf("Number of edges: %lld          \n", num_edges);

  edge_source_id = (int *)malloc(num_edges*sizeof(int));
  edge_target_id = (int *)malloc(num_edges*sizeof(int));
  edge_weight = (double *)malloc(num_edges*sizeof(double));
  if (edge_source_id == NULL || edge_target_id == NULL || edge_weight == NULL)
  {
    printf("Error: memory allocation failed!\n");
    exit(1);
  }

  fin = fopen(network_file, "rb");
  num_vertices = 0;
  for (int k = 0; k != num_edges; k++)
  {
    fscanf(fin, "%s %s %lf", name_v1, name_v2, &weight);

    if (k % 10000 == 0)
    {
      printf("Reading edges: %.3lf%%%c", k / (double)(num_edges + 1) * 100, 13);
      fflush(stdout);
    }

    vid = SearchHashTable(name_v1);
    if (vid == -1) vid = AddVertex(name_v1);
    vertex[vid].degree += weight;
    edge_source_id[k] = vid;

    vid = SearchHashTable(name_v2);
    if (vid == -1) vid = AddVertex(name_v2);
    vertex[vid].degree += weight;
    edge_target_id[k] = vid;

    edge_weight[k] = weight;
  }
  fclose(fin);
  printf("Number of vertices: %d          \n", num_vertices);
}
	void CDX9Renderer::Line(point p1, point p2, const color& c1, const color& c2)
	{
		// No support for textured lines
		SetTexture(NULL);

		BeginBatch(batch_lines);
		CBatch_Draw* draw_op = reinterpret_cast<CBatch_Draw*>(batch.back());

		AddVertex(c1.getD3DCOLOR(), p1, 0.0f, 0.0f);
		AddVertex(c2.getD3DCOLOR(), p2, 1.0f, 1.0f);
		draw_op->vertex_count += 2;
	}
Exemplo n.º 23
0
void LoadMeshInstanceIntoToy(CConversionScene* pScene, CConversionMeshInstance* pMeshInstance, const Matrix4x4& mParentTransformations)
{
	if (!pMeshInstance->IsVisible())
		return;

	CConversionMesh* pMesh = pMeshInstance->GetMesh();

	for (size_t m = 0; m < pScene->GetNumMaterials(); m++)
	{
		for (size_t j = 0; j < pMesh->GetNumFaces(); j++)
		{
			size_t k;
			CConversionFace* pFace = pMesh->GetFace(j);

			if (pFace->m == ~0)
				continue;

			CConversionMaterial* pMaterial = NULL;
			CConversionMaterialMap* pConversionMaterialMap = pMeshInstance->GetMappedMaterial(pFace->m);

			if (!pConversionMaterialMap)
				continue;

			if (!pConversionMaterialMap->IsVisible())
				continue;

			if (pConversionMaterialMap->m_iMaterial != m)
				continue;

			while (g_asTextures.size() <= pConversionMaterialMap->m_iMaterial)
			{
				g_asTextures.push_back(pScene->GetMaterial(pConversionMaterialMap->m_iMaterial)->GetDiffuseTexture());
				g_aaflData.push_back();
			}

			size_t iMaterial = pConversionMaterialMap->m_iMaterial;

			CConversionVertex* pVertex0 = pFace->GetVertex(0);

			for (k = 2; k < pFace->GetNumVertices(); k++)
			{
				CConversionVertex* pVertex1 = pFace->GetVertex(k-1);
				CConversionVertex* pVertex2 = pFace->GetVertex(k);

				AddVertex(iMaterial, mParentTransformations * pMesh->GetVertex(pVertex0->v), pMesh->GetUV(pVertex0->vu));
				AddVertex(iMaterial, mParentTransformations * pMesh->GetVertex(pVertex1->v), pMesh->GetUV(pVertex1->vu));
				AddVertex(iMaterial, mParentTransformations * pMesh->GetVertex(pVertex2->v), pMesh->GetUV(pVertex2->vu));
			}
		}
	}
}
Exemplo n.º 24
0
//-----------------------------------------------------------------------------
bool SimpleMesh::AddFace(const std::vector<Vector3<float> > &verts){

  unsigned int ind1, ind2, ind3;
  AddVertex(verts.at(0), ind1);
  AddVertex(verts.at(1), ind2);
  AddVertex(verts.at(2), ind3);

  Face tri(ind1, ind2, ind3);
  mFaces.push_back(tri);
  // Compute and assign a normal
  mFaces.back().normal = FaceNormal(mFaces.size() - 1);

  return true;
}
bool CFuzzyMembershipFunction::Read (std::istream& stream)
{
  // Check the fuzzy membership function type type
  EFileTypes FileType;
  stream.read((char*)&FileType, sizeof(FileType));
  if (FileType != fFuzzyMembershipFunction)
  {
    return false;
  }

  // Read in number of characters in the name.
  unsigned short NumCharsInName;
  stream.read((char*)&NumCharsInName, sizeof(NumCharsInName));

  // Read in name one character at a time.
  m_Name.erase();
  for (unsigned short s = 0; s < NumCharsInName; s++)
  {
    m_Name += stream.get();
  }

  // Read in Tnorm.
  stream.read((char*)&m_Tnorm,sizeof(m_Tnorm));

  // Read in Tconorm.
  stream.read((char*)&m_Tconorm,sizeof(m_Tconorm));

  // Read in number of CFuzzyElements in the membership function.
  long NumVertices;
  stream.read((char*)&NumVertices, sizeof(NumVertices));

  // Read in each CFuzzyElement.
  CFuzzyElement FE;
  for (long v = 0; v < NumVertices; v++)
  {
    // Read in value. 
    long Value;
    stream.read((char*)&Value, sizeof(Value));
    FE.SetValue(Value);

    // Read in membership.
    double Membership;
    stream.read((char*)&Membership, sizeof(Membership));
    FE.SetMembership(Membership);

    // Read in Tnorm. 
    ETnormOperations Tnorm;
    stream.read((char*)&Tnorm,sizeof(Tnorm));
    FE.SetTnorm(Tnorm);

    // Read in Tconorm.
    ETconormOperations Tconorm;
    stream.read((char*)&Tconorm,sizeof(Tconorm));
    FE.SetTconorm(Tconorm);

    AddVertex(FE);
  }

  return true;
}
Exemplo n.º 26
0
int LoadSU2Vertices(FILE *FilHdl, Mesh *Msh)
{
	int iVer, d, ref;
	double crd[3], bufDbl;
	char str[1024];
	
	rewind(FilHdl);
	
	Msh->NbrVer = GetSU2KeywordValue (FilHdl, "NPOIN=");
	
	if ( Msh->NbrVer > Msh->MaxNbrVer ) {
		printf("  ## ERROR: LoadSU2Vertices: INCONSISTENT NUMBER OF VERTICES.\n");
		return 0;
	}
	
  for (iVer=1; iVer<=Msh->NbrVer; iVer++) {
		
    crd[2] = 0;
		
    for (d=0; d<Msh->Dim; d++) {
      fscanf(FilHdl, "%lf", &bufDbl);
      crd[d] = bufDbl;
    }
    
    fscanf(FilHdl, "%d", &ref);
    fgets (str, sizeof str, FilHdl);
    
		AddVertex(Msh, iVer, crd);
  }
	
	return 1;
}
Exemplo n.º 27
0
int Mesh::NewVertex(int a, int b, Scalar c)
{
	Vector &A = GetVertex(a);
	Vector &B = GetVertex(b);

	return AddVertex(A*c + B*(1-c));
}
Exemplo n.º 28
0
void ProgressiveMesh(std::vector<float3> &vert, std::vector<tridata> &tri,
                     std::vector<int> &map, std::vector<int> &permutation)
{
	AddVertex(vert);  // put input data into our data structures
	AddFaces(tri);
	ComputeAllEdgeCollapseCosts(); // cache all edge collapse costs
	permutation.resize(vertices.size());  // allocate space
	map.resize(vertices.size());          // allocate space
	// reduce the object down to nothing:
	while (vertices.size() > 0) {
		// get the next vertex to collapse
		Vertex *mn = MinimumCostEdge();
		// keep track of this vertex, i.e. the collapse ordering
		permutation[mn->id] = vertices.size() - 1;
		// keep track of vertex to which we collapse to
		map[vertices.size() - 1] = (mn->collapse) ? mn->collapse->id : -1;
		// Collapse this edge
		Collapse(mn,mn->collapse);
	}
	// reorder the map Array based on the collapse ordering
	for (unsigned int i = 0; i<map.size(); i++) {
		map[i] = (map[i]==-1)?0:permutation[map[i]];
	}
	// The caller of this function should reorder their vertices
	// according to the returned "permutation".
}
void Model::AddCylinder(float radius, float height)
{
	const double M_PI = 3.14159265358979;
	int round = 6;

	uint16_t startIndex = GetNextVertexIndex();

	for(int i = 0; i <= round; i++)
	{
		double sangle = i * M_PI * 2. / round;
		for (int t = -1; t <= 1; t += 2)
		{
			Vector3f v = Vector3f(cos(sangle) * radius, sin(sangle) * radius, t * height);
			AddVertex(Vertex(v, Color(127, 0, 127, 255), float(i), float(t), Vector3f(cos(sangle), sin(sangle), 0)));
		}
	}

	// Renumber indices
	for (uint16_t s = 0; s < round; s++)
	{
		uint16_t s1 = s + 1;
		auto get = [&](uint16_t s, uint16_t t){
			return s * 2 + t + startIndex;
		};
		AddTriangle(get(s, 0),
			get(s, 1),
			get(s1, 0));
		AddTriangle(get(s1, 0),
			get(s, 1),
			get(s1, 1));
	}
}
Exemplo n.º 30
0
int main()
{
	scanf("%d", &ivc);

	for (int i = 0; i < ivc; i++)
	{
		int x, y;

		scanf("%d%d", &x, &y);

		AddVertex(x, y);
	}

	scanf("%d", &iec);

	for (int i = 0; i < iec; i++)
	{
		int u, v;

		scanf("%d%d", &u, &v);

		AddEdge(u, v);
		AddEdge(v, u);
	}

	scanf("%d%d", &s, &t);

	Bellman_Ford();

	printf("%.2lf", V[t].shortest);

	return 0;
}