コード例 #1
0
ファイル: AxisCollection.cpp プロジェクト: EdLeming/oxsx
std::vector<size_t>
AxisCollection::UnpackIndicies(size_t index_) const{
    std::vector<size_t> indicies(fNDimensions, 0);
    for(size_t i = 0; i < fNDimensions; i++)
        indicies[i] = UnflattenIndex(index_, i);
    return indicies;
}
コード例 #2
0
ファイル: AxisCollection.cpp プロジェクト: EdLeming/oxsx
size_t 
AxisCollection::FindBin(const std::vector<double>& vals_) const{
    if (vals_.size() != fNDimensions)
        throw DimensionError("Can't find bin! wrong number of vals");

    std::vector<size_t> indicies(fNDimensions, 0);
    for (size_t i = 0; i < fNDimensions; i++)
        indicies[i] = fAxes.at(i).FindBin(vals_[i]);

    return FlattenIndicies(indicies);
}
コード例 #3
0
ファイル: ModelWriter.cpp プロジェクト: jflo/sketchup2room
void ModelWriter::writeFace(SUMeshHelperRef mesh, const Transform& transform, bool front, bool textured) {

	size_t vertexCount=0;
	SUMeshHelperGetNumVertices(mesh,&vertexCount);
	vector<SUPoint3D> verts(vertexCount);
	SUMeshHelperGetVertices(mesh,vertexCount,verts.data(),&vertexCount);

	vector<SUVector3D> normals(vertexCount);
	SUMeshHelperGetNormals(mesh,vertexCount,normals.data(),&vertexCount);

	vector<SUPoint3D> textures(vertexCount);
	
	size_t triCount = 0;
	SUMeshHelperGetNumTriangles(mesh,&triCount);

	size_t gotIndices = 0;
	vector<size_t> indicies(triCount*3);
	SUResult res = SUMeshHelperGetVertexIndices(mesh,triCount*3,indicies.data(),&gotIndices);
	assert(res == SU_ERROR_NONE);

	if(textured) {
		if(front) {
			SUMeshHelperGetFrontSTQCoords(mesh,vertexCount,textures.data(),&vertexCount);
		} else {
			SUMeshHelperGetBackSTQCoords(mesh,vertexCount,textures.data(),&vertexCount);
		}
	}
	float normalScale = 1.0f;
	if(!front) {
		normalScale = -1.0f;
	}
	
	bool flip = !front;

	SUVector3D xFlipTest = xaxis * transform;
	if(xFlipTest.x < 0) {
		flip = !flip;
	}

	SUVector3D yFlipTest = yaxis * transform;
	if(yFlipTest.y < 0) {
		flip = !flip;
	}
	
	for(size_t t = 0; t < triCount; t++) {
			
		m_Faces << "f ";

		for(int i=0; i<3; i++) {

			int j = (t*3) + (flip ? 2-i : i);
			
			m_Faces << getIndexedPos(verts[indicies[j]]*transform) << "/";
			
			if(textured)
				m_Faces << getIndexedTex(textures[indicies[j]]);
			
			m_Faces << "/" <<  getIndexedNormal(normals[indicies[j]]*normalScale*transform) << " ";
		}

		m_Faces << endl;
	}

}
コード例 #4
0
ファイル: LightSkull.cpp プロジェクト: tczzyzymj/Prectice
void LightSkull::BuildSkullGeometries()
{
    HRESULT hr = S_FALSE;

    std::ifstream fin;
    fin.open("Models/skull.txt", std::ifstream::in);

    if (!fin)
    {
        throw std::exception();
    }

    UINT vertexCount = 0;
    UINT triangleCount = 0;

    std::string ignore;
    fin >> ignore >> vertexCount;

    fin >> ignore >> triangleCount;
    fin >> ignore >> ignore >> ignore >> ignore;

    std::vector<CustomVertex> vertices(vertexCount);

    for (UINT i = 0; i < vertexCount; ++i)
    {
        fin >> vertices[i].Pos.x >> vertices[i].Pos.y >> vertices[i].Pos.z;
        fin >> vertices[i].Normal.x >> vertices[i].Normal.y >> vertices[i].Normal.z;
    }

    fin >> ignore >> ignore >> ignore;

    m_skullIndexCount = 3 * triangleCount;
    std::vector<UINT> indicies(m_skullIndexCount);
    for (UINT i = 0; i < m_skullIndexCount; ++i)
    {
        fin >> indicies[i];
    }

    fin.close();

    D3D11_BUFFER_DESC indexBD;
    ZeroMemory(&indexBD, sizeof(D3D11_BUFFER_DESC));
    indexBD.Usage = D3D11_USAGE_IMMUTABLE;
    indexBD.BindFlags = D3D11_BIND_INDEX_BUFFER;
    indexBD.CPUAccessFlags = 0;
    indexBD.ByteWidth = sizeof(UINT) * m_skullIndexCount;
    indexBD.MiscFlags = 0;
    indexBD.StructureByteStride = 0;
    D3D11_SUBRESOURCE_DATA indexSubResource;
    ZeroMemory(&indexSubResource, sizeof(D3D11_SUBRESOURCE_DATA));
    indexSubResource.pSysMem = &indicies[0];
    hr = m_d3dDevice->CreateBuffer(&indexBD, &indexSubResource, &m_skullIndexBuffer);
    D3DHelper::ThrowIfFailed(hr);

    D3D11_BUFFER_DESC vertexBD;
    ZeroMemory(&vertexBD, sizeof(D3D11_BUFFER_DESC));
    vertexBD.Usage = D3D11_USAGE_IMMUTABLE;
    vertexBD.BindFlags = D3D11_BIND_VERTEX_BUFFER;
    vertexBD.ByteWidth = sizeof(CustomVertex) * vertexCount;
    vertexBD.CPUAccessFlags = 0;
    vertexBD.MiscFlags = 0;
    vertexBD.StructureByteStride = 0;
    D3D11_SUBRESOURCE_DATA vertexSubResource;
    vertexSubResource.pSysMem = &vertices[0];
    hr = m_d3dDevice->CreateBuffer(&vertexBD, &vertexSubResource, &m_skullVertexBuffer);
    D3DHelper::ThrowIfFailed(hr);
}
コード例 #5
0
// Main function, defines the entry point for the program.
int main( int argc, char** argv )
{

    // Structure for getting video from camera or avi
    CvCapture* capture = 0;

    // Images to capture the frame from video or camera or from file
    IplImage *frame, *frame_copy = 0;

    // Input file name for avi or image file.
    const char* vectorList;
    const char* testImage;

    // Check for the correct usage of the command line
    if( argc == 2 )
    {
        //vectorList = argv[1];
        testImage = argv[1];
    }
    else
    {
        fprintf( stderr, "Usage: eigenDecomp testImage\n" );
        return -1;
    }

    // Allocate the memory storage
    storage = cvCreateMemStorage(0);

    // Create a new named window with title: result
    cvNamedWindow( "result", 1 );

    std::vector<IplImage*> images;
    std::vector<char*> labels;

    //Load Labels
    printf("Loading Labels...  ");
    FILE* f = fopen( "labels.txt", "rt" );
    if( f )
    {
        char buf[100+1];

        // Get the line from the file
        while( fgets( buf, 100, f ) )
        {

            // Remove the spaces if any, and clean up the name
            int len = (int)strlen(buf);
            while( len > 0 && isspace(buf[len-1]) )
                len--;
            buf[len] = '\0';

            char* str = (char*)malloc(sizeof(char)*100);
            memcpy(str, buf, 100);
            labels.push_back(str);
        }
        // Close the file
        fclose(f);
        printf("%d Labels loaded.\n", labels.size());
    } else
        printf("Failed.\n");

    //Load Eigenvectors:
    printf("Loading Eigenvectors...  ");
    CvFileStorage* fs2 = cvOpenFileStorage("eigenvectors.yml", NULL, CV_STORAGE_READ);
    char vectorname[50];
    CvFileNode* vectorloc = cvGetFileNodeByName(fs2, NULL, "vector0");
    for(int i = 1; vectorloc != NULL; i++) {
        images.push_back((IplImage*)cvRead(fs2, vectorloc, &cvAttrList(0,0)));
        //printf("pushed %s\n", vectorname);
        sprintf(vectorname, "vector%d", i);
        vectorloc = cvGetFileNodeByName(fs2, NULL, vectorname);
    }
    //cvReleaseFileStorage(&fs2); This may delete the images
    printf("%d Eigenvectors (and 1 average) loaded.\n", images.size()-1);

    //TODO: unfix this number! - Done!
    //printf("FLANN DIMS: %d, %d\n", 165, images.size());
    //cv::Mat mat( 165, images.size(), CV_32F );
    //flann::Matrix<float> flannmat;
    //flann::load_from_file(flannmat, "flann.dat", "flann.dat");
    //flann::Index::Index flannIndex(flannmat, flann::LinearIndexParams());
    printf("Loading Nearest Neighbor Matrix...  ");
    CvMat* flannmat;
    CvFileStorage* fs = cvOpenFileStorage("nn.yml", NULL, CV_STORAGE_READ);
    flannmat = (CvMat*)cvRead(fs, cvGetFileNodeByName(fs, NULL, "data"), &cvAttrList(0,0));
    //cvReleaseFileStorage(&fs); This will delete the matrix
    printf("Done. DIMS: %d, %d\n", flannmat->rows, flannmat->cols);
    cv::flann::Index::Index flannIndex(flannmat, cv::flann::LinearIndexParams());

    int nn_dims = flannmat->cols; //number of nearest neighbor dimensions available
    int projection_dims = images.size()-1; //number of dimensions to project into eigenspace.

    IplImage* eigenArray[projection_dims];

    IplImage* avgImage = images[0];
    for(int i = 0; i < projection_dims; i++) {
        eigenArray[i] = images[i+1];
    }

    //load test image
    printf("Loading Test Image...\n");
    IplImage* testImg = cvLoadImage(testImage, CV_LOAD_IMAGE_GRAYSCALE);
    float projection[projection_dims];

    // Project the test image onto the PCA subspace
    printf("Conducting Eigen Decomposite...\n");
    cvEigenDecomposite(
        testImg, //test object
        projection_dims, //number of eigen vectors
        (void*)eigenArray, //eigenVectors
        0, 0, //ioflags, user callback data
        avgImage, //root eigen vector
        projection);


    //print projection
    //printf("Eigenvector Coefficents:\n");
    //for(int i = 0; i < projection_dims; i++)
    //printf("%5f ", projection[i]);
    //printf("\n");

    int neighbors = 10; //to test against

    std::vector<float> proj(nn_dims);
    std::vector<float> dists(neighbors);
    std::vector<int> indicies(neighbors);
    for(int i = 0; i < nn_dims; i++)
        proj[i] = projection[i];

    flannIndex.knnSearch(proj, indicies, dists, neighbors, NULL);
    for(int i = 0; i < neighbors; i++)
        printf("Index Match0: %4d, dist: %13.3f, Label: %s\n",
               indicies[i], dists[i], labels[indicies[i]]);

    // Destroy the window previously created with filename: "result"
    cvDestroyWindow("result");
    printf("Done.\n");
    // return 0 to indicate successfull execution of the program
    return 0;
}