Ejemplo n.º 1
0
std::shared_ptr<Volume> VolLoadPVM::open()
{
    unsigned int width, height, depth, components;
    float scalex, scaley, scalez;
    std::unique_ptr<unsigned char[]> data(readPVMvolume(filename.c_str(),
                         &width, &height, &depth,
                         &components,
                         &scalex, &scaley, &scalez));
    if (!data)
        return nullptr;
    static std::map<unsigned int, Volume::DataType> components2datatype
            = {{4, Volume::DT_Float},
               {8, Volume::DT_Double},
               {1, Volume::DT_Unsigned_Char}};
    if (0 == components2datatype.count(components))
        return nullptr;
    auto volume = std::make_shared<Volume>(data, components2datatype[components],
           width, height, depth,
           scalex, scaley, scalez);
    return volume;
}
Ejemplo n.º 2
0
int RawConverter::PvmSavToRawDerVhfConverter(     const string& src,
                                                  const string& dst  )
{
    std::cout << "Converting " << src << " -> " << dst << endl;

    // reading pvm volume
    unsigned char*  volume = 0;
    unsigned        width,  height, depth, components;
    float           scaleX, scaleY, scaleZ;
    char*           srcTmp = const_cast<char*>( src.c_str() );

    volume = readPVMvolume( srcTmp,  &width,  &height, &depth,
                                &components, &scaleX, &scaleY, &scaleZ  );

    if( volume==NULL )
        return lFailed( "Can't read vpm file" );

    if( components != 1 )
        return lFailed( "The only 8-bits models are supported" );

    std::cout  << "dimensions: "
            << width << " x " << height << " x " << depth << endl
            << "scales: " << scaleX << " x " << scaleY << " x " << scaleZ
            << endl;

    // calculating derivatives
    int result =
        calculateAndSaveDerivatives( dst, volume, width,  height, depth );

    free( volume );
    if( result ) return result;

    //converting transfer function
    SavToVhfConverter( src+".sav", dst+".vhf" );

    std::cout << "done" << endl;

    return 0;
}
Ejemplo n.º 3
0
int ModelBase::load_model(const char* file_name) {
    const char *dot = strrchr(file_name, '.');
	const char supported_ext[2][10] = {".raw", ".pvm"};
	if (!dot || (strcmp(dot, supported_ext[0]) != 0 && strcmp(dot, supported_ext[1]) != 0)) {
		Logger::log("File error: Unsupported file extension (.raw|.pvm allowed)\n");
		return 1;
	}
	unsigned char *loaded_data;
	unsigned int width, height, depth, size, components = 1;
	if (strcmp(dot, supported_ext[1]) == 0) {
		Logger::log("Reading PVM file...\n");
		float scale_x, scale_y, scale_z;
		unsigned char *description, *courtesy, *parameters, *comment;
		loaded_data = readPVMvolume(file_name, &width, &height, &depth, 
			&components, &scale_x, &scale_y, &scale_z, &description, &courtesy, &parameters, &comment);
		if (loaded_data == NULL) { 
			Logger::log("Error: File not found: %s\n", file_name);
			return 1;
		}
		Logger::log("PVM file volume metadata:\nDimensions: width = %d height = %d depth = %d components = %d\n",
			width, height, depth, components);
		if (scale_x!=1.0f || scale_y!=1.0f || scale_z!=1.0f)
			printf("Real dimensions: %g %g %g\n", scale_x, scale_y, scale_z);
		if (description!=NULL)
			printf("Object description:\n%s\n",description);
		if (courtesy!=NULL)
			printf("Courtesy information:\n%s\n",courtesy);
		if (parameters!=NULL)
			printf("Scan parameters:\n%s\n",parameters);
		if (comment!=NULL)
			printf("Additonal comments:\n%s\n",comment);
		printf("\n");
		size = width * height * depth;				
		//float max_scale = MAXIMUM(scale_x, MAXIMUM(scale_y, scale_z));	// scaling - if used indexing in model is: (pos.x*(1/bound.x)) 
		//volume.bound = (-1) * make_float3(scale_x / max_scale, scale_y / max_scale, scale_z / max_scale);
	}
	if (strcmp(dot, supported_ext[0]) == 0) {
		Logger::log("Reading RAW file...\n");
		loaded_data = readRAWfile(file_name, &size);
		if (loaded_data == NULL) { 
			Logger::log("Error: File not found: %s\n", file_name);
			return 1;
		}
		printf("Enter RAW file volume dimensions (width, height, depth): ");   
		scanf("%d %d %d",&width, &height, &depth);
		if (width * height * depth != size) {
			printf("Enter RAW file volume components (bytes per voxel): ");   
			scanf("%d", &components);
			if (width * height * depth * components != size) {
				Logger::log("Error: Incorrect RAW file volume parameters\n");
				free(loaded_data);
				return 1;
			}
		}
	}
	if (components > 2) {
		Logger::log("Error: Unsupported number of components (1|2 allowed)\n");
		free(loaded_data);
		return 1;
	}
	if (components == 2) {
		Logger::log("Quantizing 16 bit volume to 8 bit using a non-linear mapping...\n");
		loaded_data = quantize(loaded_data, width, height, depth);
	}
	if (volume.data != NULL)
		free(volume.data);
	volume.dims = make_ushort3(width, height, depth);
	volume.size = size;
	volume.data = loaded_data;
	strcpy(ModelBase::file_name, file_name);
	Logger::log("File loaded: %s, volume size: %.2f MB\n\n", file_name, volume.size / (float)(1024 * 1024));
	compute_histogram();

	return 0;
}