Commit 2b70b914 authored by karius's avatar karius

added basis for evaluation

parent ba9182c3
......@@ -9,10 +9,13 @@ CUDA_LINKS = -L/usr/local/cuda-10.0/lib64/ -lcusolver -lcudart -lcublas -lcuda -
LFLAGS=-L. $(CUDA_LINKS) $(BOOST_LINKS)
eval:
nvcc --gpu-architecture=sm_61 --include-path=./ CRotationGrid.o TransformationGrid.cu -o eval
ccl:
nvcc --gpu-architecture=sm_61 --include-path=./ --device-c Density.cu Sampler.cu Particles.cu TransformationGrid.cu CRotationGrid.cu ccl_test.cu -g -G
nvcc --gpu-architecture=sm_61 --device-link Density.o ccl_test.o Sampler.o Particles.o PdbReader.o TransformationGrid.o CRotationGrid.o --output-file link.o
g++ Density.o Particles.o Sampler.o PdbReader.o CMrcReader.o TransformationGrid.o CRotationGrid.o ccl_test.o link.o -o ccl_test -L. $(CUDA_LINKS) $(BOOST_LINKS)
g++ Density.o Particles.o Sampler.o PdbReader.o CMrcReader.o TransformationGrid.o CRotationGrid.o ccl_test.o link.o -o ccl_test -L. $(CUDA_LINKS) $(BOOST_LINKS) -lpng
ccl2: CMrcReader.o
nvcc --gpu-architecture=sm_61 --include-path=./ --device-c Sampler.cu Density.cu Kernels.cu PdbReader.cu Particles.cu Labeler.cu ccl_test.cu -g -G
......
......@@ -119,6 +119,8 @@ void TransformationGrid::write_to_csv(const char * file_name){
float3 translation;
cudaMemcpy(h_scores,d_scores,*h_num_transformations*sizeof(float),cudaMemcpyDeviceToHost);
cudaDeviceSynchronize();
//Header: #rotations,#translations,#scores
fprintf(fp,"%u,%u,1\n",*h_num_rotations,*h_num_translations);
for (int i = 0; i < *h_num_transformations;i++){
h_transformation_to_shared(i,&rotation,&translation);
fprintf(fp, "%f,%f,%f,%f,%f,%f,%f,%f\n",rotation.x,rotation.y,rotation.z,rotation.w,translation.x,translation.y,translation.z,h_scores[i]);
......@@ -126,6 +128,174 @@ void TransformationGrid::write_to_csv(const char * file_name){
fclose(fp);
}
inline void setRGB(png_byte *ptr, float val)
{
int v = (int)(val * 767);
if (v < 0) v = 0;
if (v > 767) v = 767;
int offset = v % 256;
if (v<256) {
ptr[0] = 0; ptr[1] = 0; ptr[2] = offset;
}
else if (v<512) {
ptr[0] = 0; ptr[1] = offset; ptr[2] = 255-offset;
}
else {
ptr[0] = offset; ptr[1] = 255-offset; ptr[2] = 0;
}
}
//__host__
//int TransformationGrid::write_to_png(const char * filename){
// int code = 0;
// int width = 1000;
// int height = 1000;
// char * title = "KAI";
// float * buffer = (float *) malloc(width*height*sizeof(float));
// for (int i = 100*1000;i<400*1000;i++) buffer[i] = 0.2;
// FILE *fp = NULL;
// png_structp png_ptr = NULL;
// png_infop info_ptr = NULL;
// png_bytep row = NULL;
//
// // Open file for writing (binary mode)
// fp = fopen(filename, "wb");
// if (fp == NULL) {
// fprintf(stderr, "Could not open file %s for writing\n", filename);
// code = 1;
// goto finalise;
// }
//
// // Initialize write structure
// png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
// if (png_ptr == NULL) {
// fprintf(stderr, "Could not allocate write struct\n");
// code = 1;
// goto finalise;
// }
//
// // Initialize info structure
// info_ptr = png_create_info_struct(png_ptr);
// if (info_ptr == NULL) {
// fprintf(stderr, "Could not allocate info struct\n");
// code = 1;
// goto finalise;
// }
//
// // Setup Exception handling
// if (setjmp(png_jmpbuf(png_ptr))) {
// fprintf(stderr, "Error during png creation\n");
// code = 1;
// goto finalise;
// }
//
// png_init_io(png_ptr, fp);
//
// // Write header (8 bit colour depth)
// png_set_IHDR(png_ptr, info_ptr, width, height,
// 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
// PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
//
// // Set title
// if (title != NULL) {
// png_text title_text;
// title_text.compression = PNG_TEXT_COMPRESSION_NONE;
// title_text.key = "Title";
// title_text.text = title;
// png_set_text(png_ptr, info_ptr, &title_text, 1);
// }
//
// png_write_info(png_ptr, info_ptr);
//
// // Allocate memory for one row (3 bytes per pixel - RGB)
// row = (png_bytep) malloc(3 * width * sizeof(png_byte));
//
// // Write image data
// int x, y;
// for (y=0 ; y<height ; y++) {
// for (x=0 ; x<width ; x++) {
// setRGB(&(row[x*3]), buffer[y*width + x]);
// }
// png_write_row(png_ptr, row);
// }
//
// // End write
// png_write_end(png_ptr, NULL);
//
// finalise:
// if (fp != NULL) fclose(fp);
// if (info_ptr != NULL) png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
// if (png_ptr != NULL) png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
// if (row != NULL) free(row);
//
// return code;
//
//}
__host__
float3 TransformationGrid::transform(const float4& t){
//basis: 0,0,1 "north"
return make_float3(2*(t.y*t.w + t.x*t.z),2*(t.z*t.w - t.x*t.y),1-2*(t.y*t.y + t.z*t.z));
}
__host__
void TransformationGrid::evaluate(const char * file_name){
std::ifstream fstream;
fstream.open(file_name);
//rotations,translations,number of scores
uint header[3];
float buffer[8];
float4 rotation;
float3 translation;
float3 coord;
float score;
std::string line;
std::stringstream lineStream;
std::string cell;
//header
std::getline(fstream,line);
lineStream.str(line);
int h=0;
while(std::getline(lineStream,cell, ',')){
header[h] = std::stoul(cell);
h++;
}
lineStream.clear();
printf("#rotations,#translations,#scores: %u, %u, %u\n",header[0],header[1],header[2]);
int c;
int r = 0;
while(std::getline(fstream,line)){
if (r%header[1] == 0){
lineStream.str(line);
c=0;
//assumes a certain format: [q0,q1,q2,q3,t0,t1,t2,s]
while(std::getline(lineStream,cell, ','))
{
buffer[c] = std::stof(cell);
c++;
}
rotation.x = buffer[0];
rotation.y = buffer[1];
rotation.z = buffer[2];
rotation.w = buffer[3];
translation.x = buffer[4];
translation.y = buffer[5];
translation.z = buffer[6];
score = buffer[7];
coord = TransformationGrid::transform(rotation);
printf("%i %f %f %f\n",r/header[1],coord.x,coord.y,coord.z);
lineStream.clear();
}
r++;
}
fstream.close();
}
TransformationGrid::~TransformationGrid() {
// TODO Auto-generated destructor stub
}
int main (int argc, char *argv[]) {
TransformationGrid::evaluate(argv[1]);
}
......@@ -12,6 +12,19 @@
#include <utility>
#include <cuda_runtime.h>
#include <CRotationGrid.h>
#include <png.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <iterator>
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <string>
class TransformationGrid{
public:
......@@ -40,6 +53,9 @@ public:
__device__ void d_transformation_to_shared(const uint& i, float4 * const& rotation, float3 * const& translation);
__host__ void h_transformation_to_shared(const uint& i, float4 * const& rotation, float3 * const& translation);
__host__ void write_to_csv(const char * file_name);
__host__ int write_to_png(const char * filename);
static __host__ void evaluate(const char * file_name);
static __host__ float3 transform(const float4& t);
void print(void);
private:
std::pair<float4,float4> bounding_box;
......
No preview for this file type
No preview for this file type
test/test.png

643 KB | W: | H:

test/test.png

3.6 KB | W: | H:

test/test.png
test/test.png
test/test.png
test/test.png
  • 2-up
  • Swipe
  • Onion skin
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment