void PositionJavaPinButtonExample::Project (const Eegeo::Space::LatLongAltitude& location, Eegeo::v3& screenPosition)
{
	//project a 3D Ecef location to the screen
	Eegeo::m44 finalMatrix;

	Eegeo::Camera::RenderCamera renderCamera(GetGlobeCameraController().GetRenderCamera());

	Eegeo::m44::Mul (finalMatrix,
	                 renderCamera.GetProjectionMatrix(),
	                 renderCamera.GetViewMatrix());

	Eegeo::v3 local = (location.ToECEF() - renderCamera.GetEcefLocation()).ToSingle();
	Eegeo::v4 inVector(local, 1.0f);

	// get clip space coords
	Eegeo::v4 outVector = Eegeo::v4::Mul(inVector, finalMatrix);

	// divide through by w to get normalized device space coords -- range [-1, 1]
	screenPosition.SetX((outVector.GetX()/outVector.GetW()));
	screenPosition.SetY((outVector.GetY()/outVector.GetW()));
	screenPosition.SetZ((outVector.GetZ()/outVector.GetW()));

	// transform from [-1, 1] to [0, 1]
	screenPosition.SetX((screenPosition.GetX() + 1.0f) * 0.5f);
	screenPosition.SetY(1.0f - ((screenPosition.GetY() + 1.0f) * 0.5f));

	float viewport[] = {0, 0, renderCamera.GetViewportWidth(), renderCamera.GetViewportHeight()};

	// transform from [0, 1] to screen coords.
	screenPosition.SetX((screenPosition.GetX()*(viewport[2]-viewport[0])) + viewport[0]);
	screenPosition.SetY((screenPosition.GetY()*(viewport[3]-viewport[1])) + viewport[1]);
}
コード例 #2
0
ファイル: dataFile.hpp プロジェクト: caidongyun/nnP
	status_t decodeTrainingVector(string * fragment)
	{
		float readValue;
		unsigned int node;
		std::string::size_type startPos;

		unsigned int inWidth = ((nn*) theNetwork)->layerZeroWidth();
		unsigned int outWidth = ((nn*) theNetwork)->layerNWidth();
		vector<float> inVector(inWidth);
		vector<float> outVector(outWidth);

		startPos = 1;

#ifdef _DEBUG_
		cout << "Input Vector,";
#endif
		for (node = 0; node < (inWidth - 1); node++) //>
		{
			readValue = nextFValue(fragment, startPos);
			inVector[node] = readValue;
#ifdef _DEBUG_
			cout << " Node: " << node << ": " << readValue;
#endif
		}
		readValue = nextFValue(fragment, startPos, ';');
#ifdef _DEBUG_
		cout << " Node: " << node << ": " << readValue << "\n";
#endif
		inVector[node] = readValue;

#ifdef _DEBUG_
		cout << "Output Vector,";
#endif
		for (node = 0; node < (outWidth - 1); node++) //>
		{
			readValue = nextFValue(fragment, startPos);
			outVector[node] = readValue;
#ifdef _DEBUG_
			cout << " Node: " << node << ": " << readValue;
#endif
		}
		readValue = nextFValue(fragment, startPos, ')');
#ifdef _DEBUG_
		cout << " Node: " << node << ": " << readValue << "\n";
#endif
		outVector[node] = readValue;

		if (inputToTrain)
			((nn*) theNetwork)->train(&inVector, &outVector);
		else
			((nn*)theNetwork)->test(lineCount, &inVector, &outVector);

		return SUCCESS;
	}
コード例 #3
0
ArrayType*
VectorToNativeArray(const Eigen::MatrixBase<Derived>& inVector) {
    typedef typename Derived::Scalar T;
    typedef typename Derived::Index Index;

    MutableArrayHandle<T> arrayHandle
        = defaultAllocator().allocateArray<T>(inVector.size());

    T* ptr = arrayHandle.ptr();
    for (Index el = 0; el < inVector.size(); ++el)
        *(ptr++) = inVector(el);

    return arrayHandle.array();
}
コード例 #4
0
ファイル: findPath.cpp プロジェクト: paz-terra/carribbean
std::vector<hexagon*> findPath(pathParameters params)
{
    /*
    *** F represents a heurastic calculation for the path whilst G is the current known 'cost'
    */

    std::vector<hexagon*> openVec;
    std::vector<hexagon*> closedVec;

    ///Setup all tiles
    for(auto &t : params.hexs)
    {
        t.f = 9999999;
        t.g = 9999999;
    }

    ///Setup starting tile
    params.tile1->f = params.tile1->distanceTo(params.tile2); /// Heuraustics calculated by straight line distance formula
    params.tile1->g = 0;
    openVec.push_back(params.tile1);

    ///Main variable for loop; tile currently being used, it's adjecent tiles will be evaluated
    hexagon* currentTile;

    ///********************MAIN LOOP********************///

    while(openVec.size() > 0)
    {
        ///First sort the openVector
        std::sort(openVec.begin(), openVec.end(), compHexs); //CompHexes checks index of tiles and returns bool to sort

        ///Grab the lowest F scoring tile in the open list; then remove it from the open list and add it to the closed list
        currentTile = openVec.at(0);
        std::reverse(openVec.begin(), openVec.end());
        openVec.pop_back();
        closedVec.push_back(currentTile);


        ///If Current Tile is goal return path
        if(currentTile->index == params.tile2->index)
        {
            ///Grab the path before deleting as much data as possible; All data must be stored simultaniously due to the futures being collected later; Large maps can lead to a large RAM usage
            auto ret =  buildPath(currentTile);
            std::vector<hexagon> a;
            std::vector<hexagon*> b;
            params.hexs = a;
            openVec = b;
            closedVec = b;
            return ret;
        }


        for(auto &adj : currentTile->adjacentTiles(params.hexs, params.gridSize))
        {

            if(!inVector(closedVec, adj)) /// If not already evaluated (in closed list)
            {
                if(!inVector(openVec, adj) && (adj->terrain.terrain == sea || adj->terrain.terrain == town)) /// If not already queued to be evalued (in open list) then add
                    openVec.push_back(adj);

                int tentativeGScore = currentTile->g + currentTile->distanceTo(adj);

                if(tentativeGScore < adj->g) /// If distance to next tile is less than distance to current tile???
                {
                    adj->parent = currentTile;
                    adj->g = tentativeGScore;
                    adj->f = adj->g + adj->distanceTo(params.tile2);
                }
            }

        }

    }
    std::vector<hexagon*> a;
    printf("FIND PATH FAILED!\n");
    a.push_back(params.tile1);
    return a;
}
コード例 #5
0
ファイル: gpupp-test-cu.cpp プロジェクト: ugovaretto/gpupp
/// Shows how to use a high level C++ API to perform computation through OpenCL. 
void CUMatMulTest()
{
    typedef unsigned uint;

    static const std::string SEPARATOR =     
#ifdef WIN32
        "\\";
#else
        "/";
#endif
    std::string KERNEL_PATH;
    if( getenv( "CUDA_KERNEL_PATH" ) ) {
        KERNEL_PATH = std::string( getenv( "CUDA_KERNEL_PATH") ) +
                      SEPARATOR + 
                      std::string( "vecmatmul.ptx" );

    } else {
#ifdef WIN32
    KERNEL_PATH = "C:\\projects\\gpupp\\test\\vecmatmul.ptx";
#else
    KERNEL_PATH = "/project/csstaff/uvaretto/src/gpupp/test/vecmatmul.ptx";
#endif
    std::cout << "CUDA default kernel path: " << KERNEL_PATH << std::endl;
    std::cout << "Set the default CUDA kernel path "
                 "with the CUDA_KERNEL_PATH env var" << std::endl;
    }
    const std::string KERNEL_NAME( "VecMatMul" );
    const uint MATRIX_WIDTH = 1024; 
    const uint MATRIX_HEIGHT = MATRIX_WIDTH; // <- passed to OpenCL as uint
    const uint VECTOR_SIZE = MATRIX_WIDTH; // for M x V; MATRIX_HEIGHT for V x M
    const uint MATRIX_SIZE = MATRIX_WIDTH * MATRIX_HEIGHT;
    const uint MATRIX_BYTE_SIZE = sizeof( real_t ) * MATRIX_SIZE;
    const uint VECTOR_BYTE_SIZE = sizeof( real_t ) * VECTOR_SIZE;
    try
    {
        // (0) initialize
        //::cuInit(); // this sucks! it's required by CUDA, not clear why
                      // initialization cannot be performed on a per-context basis
                      // at context creation time;
                      // techiques like invoking cuInit() from a constructor won't
                      // work if the global object is defined inside a (dynamic) library;
                      // this is currently addressed by invoking the init function from
                      // within the context creation function
        // (1) init data
        Array inMatrix( MATRIX_SIZE, real_t( 0 ) );
        Array inVector( VECTOR_SIZE, real_t( 0 ) );
        Array outVector( inVector );
        iota( inMatrix.begin(), inMatrix.end(), real_t( 0 ) );
        iota( inVector.begin(), inVector.end(), real_t( 0 ) );
        // (2) create kernel
        std::string buildOutput;  // compiler output
        std::string buildOptions; // e.g. -DDOUBLE
        // NOT POSSIBLE WITH CUDA SINCE KERNEL ARE *ALWAYS* PRECOMPILED
        // const bool TRY_TO_COMPUTE_OPTIMAL_WGROUP_SIZE = true; 
        CUDAExecutionContext ec = 
            CreateContextAndKernelFromFile( 0, //<- device number; use first available
                                            KERNEL_PATH,
                                            KERNEL_NAME );
                                            //NO RUN-TIME BUILD AVAILABLE WITH CUDA
                                            //buildOutput,
                                            //buildOptions );
                                            //TRY_TO_COMPUTE_OPTIMAL_WGROUP_SIZE );
        // OpenCL only
        //std::clog << buildOutput << std::endl;
        //if( ec.wgroupSize > 0 ) std::clog << "Computed optimal workgroup size: " << ec.wgroupSize << std::endl;
        //else std::clog << "Could not compute optimal workgroup size"  << std::endl;
        // (3) allocate input and otput buffer that will be passed to kernel function
        CUMemObj  inMatD( ec.context, MATRIX_BYTE_SIZE );
        CUMemObj  inVecD( ec.context, VECTOR_BYTE_SIZE );
        CUMemObj outVecD( ec.context, VECTOR_BYTE_SIZE );
        // (4) copy data into input buffers
        CUDACopyHtoD( inMatD, &inMatrix[ 0 ] );
        CUDACopyHtoD( inVecD, &inVector[ 0 ] );
        // (5) execute kernel
        SizeArray globalWGroupSize( 1, MATRIX_HEIGHT ); 
        SizeArray  localWGroupSize( 1, 256  );
        // kernel signature:
        // void VecMatMul( const real_t* M,
        //                 uint width,
        //                 uint height,
        //                 const real_t* V,
        //                 real_t* W )
        {
			ScopedCBackTimer< PrintTimeGPU, CUDATimer > ptGPU;
            //ScopedCBackTimer< PrintTime > pt;
            InvokeKernelSync( ec, globalWGroupSize, localWGroupSize,
                                ( VArgList(),  //<- Marks the beginning of a variable argument list
                                  inMatD,
                                  MATRIX_WIDTH,
                                  MATRIX_HEIGHT,
                                  inVecD,
                                  outVecD
                                )              //<- Marks the end of a variable argument list
                             );
        }
        // (6) read back results
        CUDACopyDtoH( outVecD, &outVector[ 0 ] );
        // print first two and last elements
        std::cout << "vector[0]    = " << outVector[ 0 ] << '\n';
        std::cout << "vector[1]    = " << outVector[ 1 ] << '\n';
        std::cout << "vector[last] = " << outVector.back() << std::endl;
        // (7) release resources: done automatically by resouce wrapper destructor
    }
    catch( const std::exception& e )
    {
        std::cerr << e.what() << std::endl;
    }
}