Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Component support for datasets #11

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace pbnj {
int dataXDim;
int dataYDim;
int dataZDim;
unsigned int dataNumComponents;

int imageWidth;
int imageHeight;
Expand Down
3 changes: 2 additions & 1 deletion include/DataFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace pbnj {
class DataFile {

public:
DataFile(int x, int y, int z);
DataFile(int x, int y, int z, unsigned int components=1);
~DataFile();

void loadFromFile(std::string filename, std::string variable="",
Expand All @@ -30,6 +30,7 @@ namespace pbnj {
unsigned long int yDim;
unsigned long int zDim;
unsigned long int numValues;
unsigned int numComponents;

float minVal; // these should
float maxVal; //
Expand Down
5 changes: 3 additions & 2 deletions include/TimeSeries.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ namespace pbnj {
class TimeSeries {

public:
TimeSeries(std::vector<std::string> filenames, int x, int y, int z);
TimeSeries(std::vector<std::string> filenames, int x, int y, int z, unsigned int components=1);
TimeSeries(std::vector<std::string> filenames, std::string varname,
int x, int y, int z);
int x, int y, int z, unsigned int components=1);
~TimeSeries();

Volume *getVolume(unsigned int index);
Expand All @@ -38,6 +38,7 @@ namespace pbnj {
int xDim;
int yDim;
int zDim;
unsigned int numComponents;
unsigned int dataSize;
unsigned int maxVolumes;
unsigned int currentVolumes;
Expand Down
4 changes: 2 additions & 2 deletions include/Volume.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ namespace pbnj {
public:
//Volume(DataFile *df);
Volume(std::string filename, int x, int y, int z,
bool memmap=false);
bool memmap=false, unsigned int components=1);
Volume(std::string filename, std::string var_name, int x, int y,
int z, bool memmap=false);
int z, bool memmap=false, unsigned int components=1);
~Volume();

void attenuateOpacity(float amount);
Expand Down
9 changes: 9 additions & 0 deletions src/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,15 @@ Configuration::Configuration(rapidjson::Document& json)
else {
this->specularity = 0.1;
}

// number of data components
// defaults to 1 in DataFile if not used
if(json.HasMember("components")) {
this->dataNumComponents = json["components"].GetUint();
}
else {
this->dataNumComponents = 1;
}
}

void Configuration::selectColorMap(std::string userInput)
Expand Down
45 changes: 38 additions & 7 deletions src/DataFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@

namespace pbnj {

DataFile::DataFile(int x, int y, int z) :
xDim(x), yDim(y), zDim(z), numValues(x*y*z), statsCalculated(false)
DataFile::DataFile(int x, int y, int z, unsigned int components) :
xDim(x), yDim(y), zDim(z), numValues(x*y*z), statsCalculated(false),
numComponents(components)
{
this->numValues = xDim * yDim * zDim;
}
Expand Down Expand Up @@ -86,9 +87,28 @@ void DataFile::loadFromFile(std::string filename, std::string var_name,
}
else {
if(memmap) {
int fd = fileno(dataFile);
this->data = (float *)mmap(NULL, this->numValues*sizeof(float),
PROT_READ, MAP_SHARED, fd, 0);
if(this->numComponents == 1) {
int fd = fileno(dataFile);
this->data = (float *)mmap(NULL, this->numValues*sizeof(float),
PROT_READ, MAP_SHARED, fd, 0);
}
else {
this->data = (float *)malloc(this->numValues * sizeof(float));
if(this->data == MAP_FAILED) {
switch(errno) {
case ENOMEM:
std::cerr << "ENOMEM out of memory" << std::endl;
break;
}
}
float *chunk = (float *)malloc(this->numComponents*sizeof(float));
for(int i = 0; i < this->numValues; i++) {
size_t numbytes = fread(chunk, sizeof(float),
this->numComponents, dataFile);
this->data[i] = std::sqrt(chunk[0]*chunk[0] +
chunk[1]*chunk[1] + chunk[2]*chunk[2]);
}
}
}
else {
this->data = (float *)malloc(this->numValues * sizeof(float));
Expand All @@ -99,8 +119,19 @@ void DataFile::loadFromFile(std::string filename, std::string var_name,
break;
}
}
size_t bytes = fread(this->data, sizeof(float), this->numValues,
dataFile);
if(this->numComponents == 1) {
size_t bytes = fread(this->data, sizeof(float),
this->numValues, dataFile);
}
else {
float *chunk = (float *)malloc(this->numComponents*sizeof(float));
for(int i = 0; i < this->numValues; i++) {
size_t numbytes = fread(chunk, sizeof(float),
this->numComponents, dataFile);
this->data[i] = std::sqrt(chunk[0]*chunk[0] +
chunk[1]*chunk[1] + chunk[2]*chunk[2]);
}
}
}
fclose(dataFile);
}
Expand Down
13 changes: 7 additions & 6 deletions src/TimeSeries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
namespace pbnj {

TimeSeries::TimeSeries(std::vector<std::string> filenames,
int x, int y, int z) :
int x, int y, int z, unsigned int components) :
dataFilenames(filenames), length(filenames.size()), xDim(x), yDim(y),
zDim(z), dataSize(x*y*z*4)
zDim(z), dataSize(x*y*z*4), numComponents(components)
{
this->volumes = new Volume*[this->length];
for(int i = 0; i < this->length; i++)
Expand All @@ -22,9 +22,9 @@ TimeSeries::TimeSeries(std::vector<std::string> filenames,
}

TimeSeries::TimeSeries(std::vector<std::string> filenames,
std::string varname, int x, int y, int z) :
std::string varname, int x, int y, int z, unsigned int components) :
dataFilenames(filenames), length(filenames.size()), dataVariable(varname),
xDim(x), yDim(y), zDim(z), dataSize(x*y*z*4)
xDim(x), yDim(y), zDim(z), dataSize(x*y*z*4), numComponents(components)
{
this->volumes = new Volume*[this->length];
for(int i = 0; i < this->length; i++)
Expand Down Expand Up @@ -110,11 +110,12 @@ Volume *TimeSeries::getVolume(unsigned int index)
// load the volume
if(this->dataVariable.empty())
this->volumes[index] = new Volume(this->dataFilenames[index],
this->xDim, this->yDim, this->zDim, this->doMemoryMap);
this->xDim, this->yDim, this->zDim, this->doMemoryMap,
this->numComponents);
else
this->volumes[index] = new Volume(this->dataFilenames[index],
this->dataVariable, this->xDim, this->yDim, this->zDim,
this->doMemoryMap);
this->doMemoryMap, this->numComponents);

// set any given attributes
if(!this->colorMap.empty())
Expand Down
9 changes: 5 additions & 4 deletions src/Volume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,25 @@

namespace pbnj {

Volume::Volume(std::string filename, int x, int y, int z, bool memmap)
Volume::Volume(std::string filename, int x, int y, int z, bool memmap,
unsigned int components)
{
this->ID = createID();
//volumes contain a datafile
//one datafile per volume, one volume per renderer/camera
this->dataFile = new DataFile(x, y, z);
this->dataFile = new DataFile(x, y, z, components);
this->loadFromFile(filename, "", memmap);

this->init();
}

Volume::Volume(std::string filename, std::string var_name, int x, int y, int z,
bool memmap)
bool memmap, unsigned int components)
{
this->ID = createID();
//volumes contain a datafile
//one datafile per volume, one volume per renderer/camera
this->dataFile = new DataFile(x, y, z);
this->dataFile = new DataFile(x, y, z, components);
this->loadFromFile(filename, var_name, memmap);

this->init();
Expand Down
9 changes: 5 additions & 4 deletions src/test/simpleVolumeRender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,19 @@ int main(int argc, const char **argv)
case pbnj::SINGLE_NOVAR:
std::cout << "Single volume, no variable" << std::endl;
volume = new pbnj::Volume(config->dataFilename, config->dataXDim,
config->dataYDim, config->dataZDim, true);
config->dataYDim, config->dataZDim, true, config->dataNumComponents);
break;
case pbnj::SINGLE_VAR:
std::cout << "Single volume, variable" << std::endl;
volume = new pbnj::Volume(config->dataFilename,
config->dataVariable, config->dataXDim, config->dataYDim,
config->dataZDim);
config->dataZDim, config->dataNumComponents);
break;
case pbnj::MULTI_NOVAR:
std::cout << "Multiple volumes, no variable" << std::endl;
timeSeries = new pbnj::TimeSeries(config->globbedFilenames,
config->dataXDim, config->dataYDim, config->dataZDim);
config->dataXDim, config->dataYDim, config->dataZDim,
config->dataNumComponents);
timeSeries->setColorMap(config->colorMap);
timeSeries->setOpacityMap(config->opacityMap);
timeSeries->setOpacityAttenuation(config->opacityAttenuation);
Expand All @@ -81,7 +82,7 @@ int main(int argc, const char **argv)
std::cout << "Multiple volumes, variable" << std::endl;
timeSeries = new pbnj::TimeSeries(config->globbedFilenames,
config->dataVariable, config->dataXDim, config->dataYDim,
config->dataZDim);
config->dataZDim, config->dataNumComponents);
timeSeries->setColorMap(config->colorMap);
timeSeries->setOpacityMap(config->opacityMap);
timeSeries->setOpacityAttenuation(config->opacityAttenuation);
Expand Down