コード例 #1
0
ファイル: poly.cpp プロジェクト: stefanha/map-files
void Poly::WritePoly ( ofstream &ofsFile_ ) const
{
/*
Polygon:
	1 uint		Texture ID
	1 Plane		Polygon plane
	1 uint		Number of vertices
	x Vertex	Vertices
*/

	ofsFile_.write ( ( char * )&TextureID, sizeof ( unsigned int ) );
	ofsFile_.write ( ( char * )&plane.n.x, sizeof ( double ) );
	ofsFile_.write ( ( char * )&plane.n.y, sizeof ( double ) );
	ofsFile_.write ( ( char * )&plane.n.z, sizeof ( double ) );
	ofsFile_.write ( ( char * )&plane.d, sizeof ( double ) );

	unsigned int ui = ( unsigned int )GetNumberOfVertices ( );

	ofsFile_.write ( ( char * )&ui, sizeof ( ui ) );

	for ( int i = 0; i < GetNumberOfVertices ( ); i++ )
	{
		ofsFile_.write ( ( char * )&verts[ i ].p.x, sizeof ( double ) );
		ofsFile_.write ( ( char * )&verts[ i ].p.y, sizeof ( double ) );
		ofsFile_.write ( ( char * )&verts[ i ].p.z, sizeof ( double ) );
		ofsFile_.write ( ( char * )&verts[ i ].tex[ 0 ], sizeof ( double ) );
		ofsFile_.write ( ( char * )&verts[ i ].tex[ 1 ], sizeof ( double ) );
	}

	if ( !IsLast ( ) )
	{
		GetNext ( )->WritePoly ( ofsFile_ );
	}
}
コード例 #2
0
double mitk::ConnectomicsNetwork::GetAverageDegree()
{
  double vertices = (double) GetNumberOfVertices();
  double edges = (double) GetNumberOfEdges();

  return ( ( edges * 2.0 ) / vertices );
}
コード例 #3
0
double mitk::ConnectomicsNetwork::GetConnectionDensity()
{
  double vertices = (double) GetNumberOfVertices();
  double edges = (double) GetNumberOfEdges();
  double numberOfPossibleEdges = vertices * ( vertices - 1 ) / 2 ;

  return ( edges / numberOfPossibleEdges );
}
コード例 #4
0
inline void TestGetCondensationGraph(const std::vector<Edge> list_of_edges, int vertices_amount, 
                const std::vector< std::set<int> >& components) {
    try {
	auto graph = MakeCompactGraph(list_of_edges, vertices_amount);
        std::vector<int> vertex_component_number(graph->GetNumberOfVertices());

        for (size_t component_index = 0; component_index < components.size(); ++component_index) {   
            for (const auto& vertex : components[component_index]) {
                vertex_component_number[vertex] = component_index;
            }
        }
  
        std::set<Edge> right_set_of_condensation_graph_edges;
        for (int vertex = 0; vertex < graph->GetNumberOfVertices(); ++vertex) {
            std::vector<int> vertex_incidences = graph->GetIncidenceList(vertex);

            for (size_t i = 0; i < vertex_incidences.size(); ++i) {
                int incident_vertex = vertex_incidences[i];

                if (vertex_component_number[incident_vertex] != vertex_component_number[vertex]) 
                    right_set_of_condensation_graph_edges.insert(Edge(vertex_component_number[vertex], 
                            vertex_component_number[incident_vertex]));
            }
        }

        auto condensation_graph = GetCondensationGraph(*graph, components);
        if (condensation_graph->GetNumberOfVertices() != components.size()) throw std::logic_error("FAIL");
        std::set<Edge> algo_set_of_condensation_graph_edges;
        for (int vertex = 0; vertex < condensation_graph->GetNumberOfVertices(); ++vertex) {
            std::vector<int> vertex_incidences = condensation_graph->GetIncidenceList(vertex);
        
            for (size_t i = 0; i < vertex_incidences.size(); ++i) {
                int incident_vertex = vertex_incidences[i];
                algo_set_of_condensation_graph_edges.insert(Edge(vertex, incident_vertex));
            }
        }

        if (right_set_of_condensation_graph_edges != algo_set_of_condensation_graph_edges) 
            throw std::logic_error("FAIL");
    } catch (const std::exception& ex) {
        throw std::logic_error("TestGetCondensationGraph: " + std::string(ex.what()));
    }
} 
コード例 #5
0
ファイル: poly.cpp プロジェクト: stefanha/map-files
const bool Poly::operator == ( const Poly &arg_ ) const
{
	if ( m_iNumberOfVertices == arg_.m_iNumberOfVertices )
	{
		if ( plane.d == arg_.plane.d )
		{
			if ( plane.n == arg_.plane.n )
			{
				for ( int i = 0; i < GetNumberOfVertices ( ); i++ )
				{
					if ( verts[ i ].p == arg_.verts[ i ].p )
					{
						if ( verts[ i ].tex[ 0 ] != arg_.verts[ i ].tex[ 0 ] )
						{
							return false;
						}

						if ( verts[ i ].tex[ 1 ] != arg_.verts[ i ].tex[ 1 ] )
						{
							return false;
						}
					}
					else
					{
						return false;
					}
				}

				if ( TextureID == arg_.TextureID )
				{
					return true;
				}
			}
		}
	}

	return false;
}
コード例 #6
0
ファイル: poly.cpp プロジェクト: stefanha/map-files
bool Poly::CalculatePlane ( )
{
    Vector3	centerOfMass;
    double	magnitude;
    int     i, j;

    if ( GetNumberOfVertices ( ) < 3 )
	{
		cout << "Polygon has less than 3 vertices!" << endl;

		return false;
	}

    plane.n.x		= 0.0f;
    plane.n.y		= 0.0f;
    plane.n.z		= 0.0f;
    centerOfMass.x	= 0.0f; 
    centerOfMass.y	= 0.0f; 
    centerOfMass.z	= 0.0f;

    for ( i = 0; i < GetNumberOfVertices ( ); i++ )
    {
        j = i + 1;

        if ( j >= GetNumberOfVertices ( ) )
		{
			j = 0;
		}

        plane.n.x += ( verts[ i ].p.y - verts[ j ].p.y ) * ( verts[ i ].p.z + verts[ j ].p.z );
        plane.n.y += ( verts[ i ].p.z - verts[ j ].p.z ) * ( verts[ i ].p.x + verts[ j ].p.x );
        plane.n.z += ( verts[ i ].p.x - verts[ j ].p.x ) * ( verts[ i ].p.y + verts[ j ].p.y );

        centerOfMass.x += verts[ i ].p.x;
        centerOfMass.y += verts[ i ].p.y;
        centerOfMass.z += verts[ i ].p.z;
    }

    if ( ( fabs ( plane.n.x ) < epsilon ) && ( fabs ( plane.n.y ) < epsilon ) &&
		 ( fabs ( plane.n.z ) < epsilon ) )
    {
        return false;
    }

    magnitude = sqrt ( plane.n.x * plane.n.x + plane.n.y * plane.n.y + plane.n.z * plane.n.z );

    if ( magnitude < epsilon )
	{
		return false;
	}

    plane.n.x /= magnitude;
    plane.n.y /= magnitude;
    plane.n.z /= magnitude;

    centerOfMass.x /= ( double )GetNumberOfVertices ( );
    centerOfMass.y /= ( double )GetNumberOfVertices ( );
    centerOfMass.z /= ( double )GetNumberOfVertices ( );

    plane.d = -( centerOfMass.Dot ( plane.n ) );

    return true;
}
コード例 #7
0
ファイル: poly.cpp プロジェクト: stefanha/map-files
void Poly::SortVerticesCW ( )
{
	//
	// Calculate center of polygon
	//
	Vector3	center;

	for ( int i = 0; i < GetNumberOfVertices ( ); i++ )
	{
		center = center + verts[ i ].p;
	}

	center = center / GetNumberOfVertices ( );

	//
	// Sort vertices
	//
	for ( i = 0; i < GetNumberOfVertices ( ) - 2; i++ )
	{
		Vector3	a;
		Plane	p;
		double	SmallestAngle	= -1;
		int		Smallest		= -1;

		a = verts[ i ].p - center;
		a.Normalize ( );

		p.PointsToPlane ( verts[ i ].p, center, center + plane.n );

		for ( int j = i + 1; j < GetNumberOfVertices ( ); j++ )
		{
			if ( p.ClassifyPoint ( verts[ j ].p ) != Plane::eCP::BACK )
			{
				Vector3	b;
				double	Angle;
				
				b = verts[ j ].p - center;
				b.Normalize ( );

				Angle = a.Dot ( b );

				if ( Angle > SmallestAngle )
				{
					SmallestAngle	= Angle;
					Smallest		= j;
				}
			}
		}

		if ( Smallest == -1 )
		{
			cout << "Error: Degenerate polygon!" << endl;

			abort ( );
		}

		Vertex	t			= verts[ Smallest ];
		verts[ Smallest ]	= verts[ i + 1 ];
		verts[ i + 1 ]		= t;
	}

	//
	// Check if vertex order needs to be reversed for back-facing polygon
	//
	Plane	oldPlane = plane;

	CalculatePlane ( );

	if ( plane.n.Dot ( oldPlane.n ) < 0 )
	{
		int j = GetNumberOfVertices ( );

		for ( int i = 0; i < j / 2; i++ )
		{
			Vertex v			= verts[ i ];
			verts[ i ]			= verts[ j - i - 1 ];
			verts[ j - i - 1 ]	= v;
		}
	}
}
コード例 #8
0
ファイル: poly.cpp プロジェクト: stefanha/map-files
void Poly::CalculateTextureCoordinates ( int texWidth, int texHeight, Plane texAxis[ 2 ], double texScale[ 2 ] )
{
	//
	// Calculate texture coordinates
	//
	for ( int i = 0; i < GetNumberOfVertices ( ); i++ )
	{
		double U, V;
		
		U = texAxis[ 0 ].n.Dot ( verts[ i ].p );
		U = U / ( ( double )texWidth ) / texScale[ 0 ];
		U = U + ( texAxis[ 0 ].d / ( double )texWidth );

		V = texAxis[ 1 ].n.Dot ( verts[ i ].p );
		V = V / ( ( double )texHeight ) / texScale[ 1 ];
		V = V + ( texAxis[ 1 ].d / ( double )texHeight );

		verts[ i ].tex[ 0 ] = U;
		verts[ i ].tex[ 1 ] = V;
	}

	//
	// Check which axis should be normalized
	//
	bool	bDoU = true;
	bool	bDoV = true;

	for ( i = 0; i < GetNumberOfVertices ( ); i++ )
	{
		if ( ( verts[ i ].tex[ 0 ] < 1 ) && ( verts[ i ].tex[ 0 ] > -1 ) )
		{
			bDoU = false;
		}

		if ( ( verts[ i ].tex[ 1 ] < 1 ) && ( verts[ i ].tex[ 1 ] > -1 ) )
		{
			bDoV = false;
		}
	}

	//
	// Calculate coordinate nearest to 0
	//
	if ( bDoU || bDoV )
	{
		double	NearestU = 0;
		double	U = verts[ 0 ].tex[ 0 ];

		double	NearestV = 0;
		double	V = verts[ 0 ].tex[ 1 ];

		if ( bDoU )
		{
			if ( U > 1 )
			{
				NearestU = floor ( U );
			}
			else
			{
				NearestU = ceil ( U );
			}
		}

		if ( bDoV )
		{
			if ( V > 1 )
			{
				NearestV = floor ( V );
			}
			else
			{
				NearestV = ceil ( V );
			}
		}

		for ( i = 0; i < GetNumberOfVertices ( ); i++ )
		{
			if ( bDoU )
			{
				U = verts[ i ].tex[ 0 ];

				if ( fabs ( U ) < fabs ( NearestU ) )
				{
					if ( U > 1 )
					{
						NearestU = floor ( U );
					}
					else
					{
						NearestU = ceil ( U );
					}
				}
			}

			if ( bDoV )
			{
				V = verts[ i ].tex[ 1 ];

				if ( fabs ( V ) < fabs ( NearestV ) )
				{
					if ( V > 1 )
					{
						NearestV = floor ( V );
					}
					else
					{
						NearestV = ceil ( V );
					}
				}
			}
		}

		//
		// Normalize texture coordinates
		//
		for ( i = 0; i < GetNumberOfVertices ( ); i++ )
		{
			verts[ i ].tex[ 0 ] = verts[ i ].tex[ 0 ] - NearestU;
			verts[ i ].tex[ 1 ] = verts[ i ].tex[ 1 ] - NearestV;
		}
	}
}