Example #1
0
void File::convertTo3DPoints(List &l, const TFileWords &file_content)
{
	//Convert loaded points to the list of 3D points
	for (unsigned int i = 0; i < file_content.size(); i++)
	{
		// 3D Geographic point in DD MM SS mode: <point_label> <DD_lat> <MM_lat> <SS_lat> <DD_lon> <MM_lon> <SS_lon> <H>
		if (file_content[i].size() == 8)
		{
			l.push_back(Point(file_content[i][0].c_str(), atof(file_content[i][1].c_str()) + atof(file_content[i][2].c_str()) / 60.0 + atof(file_content[i][3].c_str()) / 3600.0,
				atof(file_content[i][4].c_str()) + atof(file_content[i][5].c_str()) / 60.0 + atof(file_content[i][6].c_str()) / 3600.0, atof(file_content[i][7].c_str())));
		}

		//3D Geographic point in DD MM SS mode: <DD_lat> <MM_lat> <SS_lat> <DD_lon> <MM_lon> <SS_lon> <H>
		else if (file_content[i].size() == 7)
		{
			l.push_back(Point(atof(file_content[i][0].c_str()) + atof(file_content[i][1].c_str()) / 60.0 + atof(file_content[i][2].c_str()) / 3600.0,
				atof(file_content[i][3].c_str()) + atof(file_content[i][4].c_str()) / 60.0 + atof(file_content[i][5].c_str()) / 3600.0, atof(file_content[i][6].c_str())));
		}

		//Common 3D point with label
		else if (file_content[i].size() == 4)
		{
			l.push_back(Point(file_content[i][0].c_str(), atof(file_content[i][1].c_str()), atof(file_content[i][2].c_str()), atof(file_content[i][3].c_str())));
		}

		//Common 3D point without label
		else if (file_content[i].size() == 3)
		{
			l.push_back(Point(atof(file_content[i][0].c_str()), atof(file_content[i][1].c_str()), atof(file_content[i][2].c_str())));
		}

		//Throw exception
		else throw BadDataException("BadDataException: unknown data format. ", "Can't read the file.");
	}
}	
Example #2
0
void SpriteDefinition::Load(const string& path, const System& system)
{
	FileHandle file(path, "rb");

	SpriteHeader sh;

	if (SDL_RWread(file, &sh, sizeof(SpriteHeader), 1) != 1)
	{
		throw BadDataException(path, "failed to read sprite header");
	}

	if (sh.m_magic != SPRITEMAGIC)
	{
		throw BadDataException(path, "invalid sprite file");
	}

	m_frames.resize(sh.m_numFrames);

	if (SDL_RWread(file, &m_frames[0], sizeof(Frame), sh.m_numFrames) != sh.m_numFrames)
	{
		throw BadDataException(path, "failed to read sprite frames");
	}

	m_sequences.resize(sh.m_numSequences);

	if (SDL_RWread(file, &m_sequences[0], sizeof(Sequence), sh.m_numSequences) != sh.m_numSequences)
	{
		throw BadDataException(path, "failed to read sprite sequences");
	}

	m_ticksPerFrame = sh.m_ticksPerFrame;

	string texturePath;
	texturePath.reserve(sh.m_texturePathLength);
	if (SDL_RWread(file, &texturePath[0], 1, sh.m_texturePathLength) != sh.m_texturePathLength)
	{
		throw BadDataException(path, "failed to read sprite texture path");
	}

	m_texturePage = system.LoadTexture(texturePath);
}
Example #3
0
typename Point::Type TurningFunction::compare2PolyLinesUsingTurningFunction ( const Container <Point > &pl1, const Container <Point> &pl2, const TTurningFunctionRotationMethod & rotation_method,
                const TTurningFunctionScaleMethod & scale_method )
{
        //Compare 2 polylines using difference of turning functions
        typename TTurningFunction <typename Point::Type>::Type tf1, tf2;

        //Not enough points, throw exception
        if ( pl1.size() < 3 || pl2.size() < 3 )
        {
                throw BadDataException ( "BadDataException: not enough points. ", "Can not compare 2 polylines using Turning function." );
        }

        //Compute turning functions
        computeTurningFunctionPolyLine ( pl1 , tf1, rotation_method, scale_method );
        computeTurningFunctionPolyLine ( pl2 , tf2, rotation_method, scale_method );

        //Compute difference of turning functions
        return compareTurningFunctions <typename Point::Type> ( tf1, tf2, rotation_method );
}
void HomotheticTransformation2D::transform ( const Container <Point1 *, destructable> &global_points, const Container <Point2 *, destructable2> &local_points, Container <Point3 *, destructable3> &transformed_points, const TTransformationKeyHomothetic2D <typename Point1::Type> & key_homothetic )
{
        //Transform all points using 2D Homothetic transformation

        //List of transformed points not empty
        if ( transformed_points.size() != 0 )
        {
                throw BadDataException ( "BadDataException: list of tranformed points is not empty. ", "Can not compute Homothetic 2D transformation." );
        }

        for ( unsigned int i = 0; i < local_points.size(); i++ )
        {
                //Reduce coordinates
                const typename Point1::Type x_red_local = local_points [i]->getX() - key_homothetic.x_mass_local,
                                            y_red_local = local_points [i]->getY() - key_homothetic.y_mass_local;

                //Transform point, add coordinates center of mass
                const typename Point1::Type x_transform = key_homothetic.c * x_red_local + key_homothetic.x_mass_global,
                                            y_transform = key_homothetic.c * y_red_local + key_homothetic.y_mass_global;

                //Add point to the list
                transformed_points.push_back ( new Point3 ( x_transform, y_transform ) );
        }
}
void HomotheticTransformation2D::getTransformKey ( const Container <Point1 *, destructable> &global_points, const Container <Point2 *, destructable2> &local_points, typename TWeights <typename Point1::Type> ::Type & weights,
                TTransformationKeyHomothetic2D <typename Point1::Type> & key_homothetic )
{
        //Get transformation key for weighted transformation
        const unsigned int n_global = global_points.size(), n_local = local_points.size();
        typename Point1::Type sumx_local = 0, sumy_local = 0, sumx_global = 0, sumy_global = 0;

        //Not enough points
        if ( ( n_global < 2 ) || ( n_local < 2 ) )
        {
                throw  BadDataException ( "BadDataException: not enough points. ", "Can not compute Homothetic 2D transformation key. \n" );
        }

        //Less local points
        if ( n_global > n_local )
        {
                throw  BadDataException ( "BadDataException: less local points than global points. ", "Can not compute Homothetic 2D transformation key. \n" );
        }

        //Compute sums of coordinates
        typename Point1::Type sum_weights = 0;

        for ( unsigned int i = 0; i < n_global; i++ )
        {
                sumx_local += weights[i] * local_points [i]->getX();
                sumy_local += weights[i] * local_points [i]->getY();
                sumx_global += weights[i] * global_points [i]->getX();
                sumy_global += weights[i] * global_points [i]->getY();

                sum_weights += weights[i];
        }

        //Compute center of mass
        key_homothetic.x_mass_local = sumx_local / ( sum_weights );
        key_homothetic.y_mass_local = sumy_local / ( sum_weights );
        key_homothetic.x_mass_global = sumx_global / ( sum_weights );
        key_homothetic.y_mass_global = sumy_global / ( sum_weights );

        //Remeber k
        key_homothetic.k = sum_weights;

        //Reduction of coordinates to the center of mass
        typename Point1::Type x_red_local, y_red_local, xred_global, yred_global, k = 0;

        //Process all points
        key_homothetic.J = 0;

        for ( unsigned int i = 0; i < n_global; i++ )
        {
                //Compute reduced coordinates
                x_red_local = local_points [i]->getX() - key_homothetic.x_mass_local;
                y_red_local = local_points [i]->getY() - key_homothetic.y_mass_local;
                xred_global = global_points [i]->getX() - key_homothetic.x_mass_global;
                yred_global = global_points [i]->getY() - key_homothetic.y_mass_global;

                //Compute coefficients of transformation
                key_homothetic.J += weights[i] * ( x_red_local * x_red_local + y_red_local * y_red_local );
                k += weights[i] * ( xred_global * x_red_local + yred_global * y_red_local );
        }

        //Throw exception
        if ( key_homothetic.J == 0 )
        {
                throw  MathZeroDevisionException <typename Point1::Type> ( "MathZeroDevisionException: can not compute Homothetic 2D transformation, ", " divider = ", key_homothetic.J );
        }

        //Transformation coefficient: only scale
        key_homothetic.c = fabs ( k ) / key_homothetic.J;
}