Skip to content

Commit

Permalink
Added support for multiple volumes
Browse files Browse the repository at this point in the history
  • Loading branch information
favreau committed Oct 19, 2016
1 parent 786c245 commit ab00aa4
Show file tree
Hide file tree
Showing 34 changed files with 605 additions and 262 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
./
CMake/common/
Deflect/
FlatBuffers/
Expand All @@ -6,10 +7,20 @@ Servus/
ZeroBuf/
build/
ZeroEQ/
Brion/
Lexis/
Lunchbox/
MVDTool/
httpxx/
vmmlib/
CMakeFiles
.DS_Store
*~
*#
*.autosave
*.files
*.config
*.includes
*.creator*
*.user

6 changes: 6 additions & 0 deletions .gitsubprojects
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# -*- mode: cmake -*-
git_subproject(vmmlib https://github.com/Eyescale/vmmlib.git 10d93e6)
git_subproject(Servus https://github.com/HBPVIS/Servus.git fd59b92)

# ZeroEQ and HTTP messaging
git_subproject(ZeroBuf https://github.com/HBPVIS/ZeroBuf.git 346c1b5)
git_subproject(ZeroEQ https://github.com/HBPVis/ZeroEQ.git 6de9a8a)
git_subproject(Lexis https://github.com/HBPVis/Lexis.git 06819cc)

# Streaming to display walls
git_subproject(Deflect https://github.com/BlueBrain/Deflect.git 1cb94bc)

# Data access
git_subproject(Brion https://github.com/BlueBrain/Brion.git 5855581)
13 changes: 6 additions & 7 deletions brayns/Brayns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,14 @@ struct Brayns::Impl
if(!geometryParameters.getXYZBFile().empty())
_loadXYZBFile();

if(!volumeParameters.getFilename().empty())
if(!volumeParameters.getFilename().empty() || !volumeParameters.getFolder().empty())
{
const Vector3ui& volumeDimensions = scene->getVolumeHandler()->getDimensions();
const Vector3f& volumeScale = volumeParameters.getScale();
const Vector3ui& volumeDimensions = scene->getVolumeHandler()->getDimensions( 0.f );
const Vector3f& volumeElementSpacing = volumeParameters.getElementSpacing();
Boxf& worldBounds = scene->getWorldBounds();
worldBounds.merge( Vector3f( 0.f, 0.f, 0.f ));
worldBounds.merge( Vector3f( volumeDimensions ) * volumeScale );
worldBounds.merge( Vector3f( volumeDimensions ) * volumeElementSpacing );
}
scene->commitVolumeData();

if( scene->isEmpty() && !scene->getVolumeHandler() )
scene->buildDefault();
Expand Down Expand Up @@ -424,7 +423,7 @@ struct Brayns::Impl
TransferFunctionLoader transferFunctionLoader( brayns::Vector2f( 0, nbMaterials ));
transferFunctionLoader.loadFromFile(
transferFunctionFilename, *_engine->getScene( ));
_engine->getScene()->commitSimulationData();
_engine->getScene()->commitTransferFunctionData();
}

}
Expand Down Expand Up @@ -622,8 +621,8 @@ struct Brayns::Impl
TransferFunctionLoader transferFunctionLoader( DEFAULT_TRANSFER_FUNCTION_RANGE );
transferFunctionLoader.loadFromFile(
transferFunctionFilename, *_engine->getScene() );
_engine->getScene()->commitTransferFunctionData();
}
_engine->getScene()->commitSimulationData();
}
}

Expand Down
47 changes: 43 additions & 4 deletions brayns/common/scene/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <servus/uri.h>

#include <boost/filesystem.hpp>
#include <algorithm>

namespace brayns
{
Expand Down Expand Up @@ -199,7 +200,8 @@ void Scene::buildDefault( )
_materials[material]->setColor( colors[material] );
_materials[material]->setSpecularColor( WHITE );
_materials[material]->setSpecularExponent( 10.f );
_materials[material]->setReflectionIndex( material == 4 ? 0.8f : 0.f );
_materials[material]->setReflectionIndex( 0.5f );
_materials[material]->setReflectionIndex( material == 4 ? 0.1f : 0.f );
_materials[material]->setOpacity( 1.f );
for( size_t i = 0; i < 6; ++i )
{
Expand Down Expand Up @@ -517,9 +519,46 @@ VolumeHandlerPtr Scene::getVolumeHandler()
{
const std::string& volumeFile =
_parametersManager.getVolumeParameters().getFilename();
if( !_volumeHandler && !volumeFile.empty() )
_volumeHandler.reset( new VolumeHandler(
_parametersManager.getVolumeParameters(), volumeFile ));
const std::string& volumeFolder =
_parametersManager.getVolumeParameters().getFolder();

if( !_volumeHandler && ( !volumeFile.empty() || !volumeFolder.empty() ))
{
_volumeHandler.reset(
new VolumeHandler( _parametersManager.getVolumeParameters(), TM_MODULO ));
if( !volumeFile.empty() )
_volumeHandler->attachVolumeToFile( 0.f, volumeFile );
else
{
strings filenames;

boost::filesystem::directory_iterator endIter;
if( boost::filesystem::is_directory(volumeFolder))
{
for( boost::filesystem::directory_iterator dirIter( volumeFolder );
dirIter != endIter; ++dirIter )
{
if( boost::filesystem::is_regular_file(dirIter->status( )))
{
boost::filesystem::path fileExtension =
dirIter->path( ).extension( );
if( fileExtension==".raw" )
{
const std::string& filename = dirIter->path( ).string( );
filenames.push_back( filename );
}
}
}
}
std::sort(filenames.begin(), filenames.end());
float timestamp = 0.f;
for( const auto& filename: filenames )
{
_volumeHandler->attachVolumeToFile( timestamp, filename );
timestamp += 1.f;
}
}
}
}
catch( const std::runtime_error& e )
{
Expand Down
9 changes: 8 additions & 1 deletion brayns/common/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ struct ExtensionParameters
const size_t NO_MATERIAL = -1;
const size_t NB_MAX_MATERIALS = 200;
const size_t NB_SYSTEM_MATERIALS = 4;
const size_t MATERIAL_SYSTEM = NB_MAX_MATERIALS - NB_SYSTEM_MATERIALS;
const size_t MATERIAL_SYSTEM = NB_MAX_MATERIALS - NB_SYSTEM_MATERIALS - 1;
const size_t MATERIAL_SKYBOX = MATERIAL_SYSTEM + 0;
const size_t MATERIAL_BOUNDING_BOX = MATERIAL_SYSTEM + 1;
const size_t MATERIAL_SIMULATION = MATERIAL_SYSTEM + 2;
Expand Down Expand Up @@ -299,6 +299,13 @@ enum CameraType
CT_PANORAMIC
};

enum TimestampMode
{
TM_DEFAULT,
TM_MODULO,
TM_BOUNDED
};

}

#endif // TYPES_H
179 changes: 146 additions & 33 deletions brayns/common/volume/VolumeHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,60 +28,173 @@
#include <sys/stat.h>
#include <fcntl.h>

namespace
{
const int NO_DESCRIPTOR = -1;
}

namespace brayns
{

VolumeHandler::VolumeHandler(
const VolumeParameters& volumeParameters,
const std::string& volumeFile )
: _memoryMapPtr( 0 )
, _cacheFileDescriptor( -1 )
, _dimensions( volumeParameters.getDimensions() )
VolumeParameters& volumeParameters,
const TimestampMode timestampMode )
: _volumeParameters( &volumeParameters )
, _currentTimestamp( std::numeric_limits<float>::max( ))
, _timestampRange( std::numeric_limits<float>::max(), std::numeric_limits<float>::min( ))
, _timestampMode( timestampMode )
{
BRAYNS_INFO << "Attaching " << volumeFile << " to current scene" << std::endl;
_cacheFileDescriptor = open( volumeFile.c_str(), O_RDONLY );
if( _cacheFileDescriptor == -1 )
BRAYNS_THROW( std::runtime_error( "Failed to attach " + volumeFile ));
}

struct stat sb;
if( ::fstat( _cacheFileDescriptor, &sb ) == -1 )
BRAYNS_THROW( std::runtime_error( "Failed to attach " + volumeFile ));
VolumeHandler::~VolumeHandler()
{
_volumeDescriptors.clear();
}

_memoryMapPtr = ::mmap(
0, sb.st_size, PROT_READ, MAP_PRIVATE, _cacheFileDescriptor, 0 );
if( _memoryMapPtr == MAP_FAILED )
void VolumeHandler::attachVolumeToFile( const float timestamp, const std::string& volumeFile )
{
_volumeDescriptors[ timestamp ].reset(
new VolumeDescriptor( volumeFile, _volumeParameters->getDimensions( )));
for( const auto& volumeDescriptor: _volumeDescriptors )
{
_memoryMapPtr = 0;
::close( _cacheFileDescriptor );
BRAYNS_THROW( std::runtime_error( "Failed to attach " + volumeFile ));
_timestampRange.x() = std::min( _timestampRange.x(), volumeDescriptor.first );
_timestampRange.y() = std::max( _timestampRange.y(), volumeDescriptor.first );
}
BRAYNS_INFO << "Attached " << volumeFile << " to timestamp "
<< timestamp << " " << _timestampRange << std::endl;
}

_size = sb.st_size;
void* VolumeHandler::getData( const float timestamp )
{
const float ts = _getBoundedTimestamp( timestamp );
if( ts != _currentTimestamp &&
_volumeDescriptors.find( ts ) != _volumeDescriptors.end( ))
{
if( _volumeDescriptors.find( _currentTimestamp ) != _volumeDescriptors.end( ))
_volumeDescriptors[ _currentTimestamp ]->unmap();
_currentTimestamp = ts;
_volumeDescriptors[ _currentTimestamp ]->map();
}
return _volumeDescriptors[ _currentTimestamp ]->getMemoryMapPtr();
}

BRAYNS_INFO << "Volume size : " << _size << " bytes ["
<< _size / 1048576 << " MB]" << std::endl;
BRAYNS_INFO << "Volume dimensions: " << _dimensions << std::endl;
BRAYNS_INFO << "Successfully attached to " << volumeFile << std::endl;
float VolumeHandler::getEpsilon(
const float timestamp ,
const Vector3f& elementSpacing,
const uint16_t samplesPerRay )
{
const float ts = _getBoundedTimestamp( timestamp );
if( _volumeDescriptors.find( ts ) != _volumeDescriptors.end( ))
{
Vector3f diag = Vector3f( _volumeDescriptors[ ts ]->getDimensions( )) * elementSpacing;
return std::max(diag.x(), std::max( diag.y(), diag.z())) / float( samplesPerRay );
}
else
{
BRAYNS_ERROR << "No volume is attached to the specified timestamp: "
<< timestamp << std::endl;
return 0;
}
}

VolumeHandler::~VolumeHandler()
const Vector3ui VolumeHandler::getDimensions( const float timestamp )
{
if( _memoryMapPtr )
::munmap( (void *)_memoryMapPtr, _size );
float ts = _getBoundedTimestamp( timestamp );
if( _volumeDescriptors.find( ts ) != _volumeDescriptors.end( ))
return _volumeDescriptors[ ts ]->getDimensions();
else
{
BRAYNS_ERROR << "No volume is attached to the specified timestamp: "
<< timestamp << std::endl;
return Vector3ui( 0.f );
}
}

if( _cacheFileDescriptor != -1 )
::close( _cacheFileDescriptor );
uint64_t VolumeHandler::getSize( const float timestamp )
{
const float ts = _getBoundedTimestamp( timestamp );
if( _volumeDescriptors.find( ts ) != _volumeDescriptors.end( ))
return _volumeDescriptors[ ts ]->getSize();
else
{
BRAYNS_ERROR << "No volume is attached to the specified timestamp: "
<< timestamp << std::endl;
return 0;
}
}

void* VolumeHandler::getData()
float VolumeHandler::_getBoundedTimestamp( const float timestamp )
{
return _memoryMapPtr;
float result;
switch( _timestampMode )
{
case TM_MODULO:
result = size_t( timestamp + _timestampRange.x( )) % _volumeDescriptors.size();
break;
case TM_BOUNDED:
result = std::max( std::min( timestamp, _timestampRange.y( )), _timestampRange.x( ));
case TM_DEFAULT:
default:
result = timestamp;
}
return result;
}

VolumeHandler::VolumeDescriptor::VolumeDescriptor(
const std::string& filename,
const Vector3f& dimensions )
: _filename( filename )
, _memoryMapPtr( 0 )
, _cacheFileDescriptor( NO_DESCRIPTOR )
, _dimensions( dimensions )
{
}

VolumeHandler::VolumeDescriptor::~VolumeDescriptor()
{
unmap();
}

float VolumeHandler::getEpsilon( const Vector3f& scale, const uint16_t samplesPerRay )
void VolumeHandler::VolumeDescriptor::map()
{
Vector3f diag = Vector3f(_dimensions) * scale;
return std::max(diag.x(), std::max( diag.y(), diag.z())) / float( samplesPerRay );
_cacheFileDescriptor = open( _filename.c_str(), O_RDONLY );
if( _cacheFileDescriptor == NO_DESCRIPTOR )
{
BRAYNS_ERROR << "Failed to attach " << _filename << std::endl;
return;
}

struct stat sb;
if( ::fstat( _cacheFileDescriptor, &sb ) == NO_DESCRIPTOR )
{
BRAYNS_ERROR << "Failed to attach " << _filename << std::endl;
return;
}

_size = sb.st_size;
_memoryMapPtr = ::mmap( 0, _size, PROT_READ, MAP_PRIVATE, _cacheFileDescriptor, 0 );
if( _memoryMapPtr == MAP_FAILED )
{
_memoryMapPtr = 0;
::close( _cacheFileDescriptor );
_cacheFileDescriptor = NO_DESCRIPTOR;
BRAYNS_ERROR << "Failed to attach " << _filename << std::endl;
return;
}
}

void VolumeHandler::VolumeDescriptor::unmap()
{
if( _memoryMapPtr )
{
::munmap( (void*)_memoryMapPtr, _size );
_memoryMapPtr = 0;
}
if( _cacheFileDescriptor != NO_DESCRIPTOR )
{
::close( _cacheFileDescriptor );
_cacheFileDescriptor = NO_DESCRIPTOR;
}
}

}
Loading

0 comments on commit ab00aa4

Please sign in to comment.