void CanvasRendererWidget::initialize() { QProcessorWidget::initialize(); CanvasRenderer* canvasRenderer = dynamic_cast<CanvasRenderer*>(processor_); tgtAssert(canvasRenderer, "CanvasRenderer expected"); if (!VoreenApplication::app()) { LERRORC("voreen.qt.CanvasRendererWidget", "VoreenApplication not instantiated"); throw new VoreenException("VoreenApplication not instantiated"); } NetworkEvaluator* evaluator = VoreenApplication::app()->getNetworkEvaluator(); if (!evaluator) { LERRORC("voreen.qt.CanvasRendererWidget", "No evaluator assigned to VoreenApplication"); throw new VoreenException("No evaluator assigned to VoreenApplication"); } canvasWidget_ = new tgt::QtCanvas("", tgt::ivec2(getSize().x, getSize().y), tgt::GLCanvas::RGBADD, this, true, 0); canvasWidget_->setMinimumSize(64, 64); canvasWidget_->setMouseTracking(true); // for receiving mouse move events without a pressed button QGridLayout* layout = new QGridLayout; layout->setContentsMargins(0, 0, 0, 0); layout->addWidget(canvasWidget_, 0, 0); setLayout(layout); //show(); VoreenPainter* painter = new VoreenPainter(canvasWidget_, evaluator, canvasRenderer); canvasWidget_->setPainter(painter); painter->initialize(); canvasRenderer->setCanvas(canvasWidget_); initialized_ = true; }
VolumeRepresentation* RepresentationConverterLoadFromDiskToGL::convert(const VolumeRepresentation* source) const { // convert from disk to ram RepresentationConverterLoadFromDisk diskToRam; VolumeRepresentation* volumeRam = 0; if (diskToRam.canConvert(source)) volumeRam = diskToRam.convert(source); if (!volumeRam) { LERRORC("voreen.RepresentationConverterLoadFromDiskToGL", "Failed to create RAM volume from disk volume"); return 0; } // convert from ram to disk RepresentationConverterUploadGL ramToGL; VolumeRepresentation* volumeGL = 0; if (ramToGL.canConvert(volumeRam)) volumeGL = ramToGL.convert(volumeRam); if (!volumeGL) { LERRORC("voreen.RepresentationConverterLoadFromDiskToGL", "Failed to create GL volume from RAM volume"); } // free volumeRam delete volumeRam; volumeRam = 0; return volumeGL; }
void OpenCLModule::initCL() throw (VoreenException) { if (opencl_) return; opencl_ = new cl::OpenCL(); const std::vector<cl::Platform>& platforms = opencl_->getPlatforms(); if (platforms.empty()) { LERRORC("voreen.OpenCLModule", "Found no OpenCL platforms!"); throw VoreenException("Found no OpenCL platforms"); } const std::vector<cl::Device*>& devices = platforms[0].getDevices(); if (devices.empty()) { LERRORC("voreen.OpenCLModule", "Found no devices in platform!"); throw VoreenException("Found no devices in platform"); } device_ = devices[0]; if (glSharing_) { LINFO("Using OpenGL sharing"); context_ = new cl::Context(cl::Context::generateGlSharingProperties(), device_); } else { LINFO("No OpenGL sharing"); context_ = new cl::Context(device_); } queue_ = new cl::CommandQueue(context_, device_); }
std::vector<std::pair<std::string, std::string> > Property::getCompatibleEvaluators(const voreen::Property* dst) const{ std::vector<std::pair<std::string, std::string> > result; if (!VoreenApplication::app()) { LERRORC("voreen.property", "VoreenApplication not instantiated"); return result; } const std::vector<VoreenModule*>& modules = VoreenApplication::app()->getModules(); for (size_t m=0; m<modules.size(); m++) { const std::vector<LinkEvaluatorFactory*>& factories = modules.at(m)->getLinkEvaluatorFactories(); for (size_t i=0; i<factories.size(); i++) { std::vector<std::pair<std::string, std::string> > evaluators = factories.at(i)->getCompatibleLinkEvaluators(this, dst); result.insert(result.end(), evaluators.begin(), evaluators.end()); } } // put size link evaluator to front (HACK) /*for (size_t i=1; i<result.size(); i++) { if (result.at(i).first == "LinkEvaluatorRenderSize") { std::swap(result.at(0), result.at(i)); break; } }*/ return result; }
PyVoreenQt::PyVoreenQt() { if (Py_IsInitialized()) Py_InitModule("voreenqt", voreenqt_methods); else LERRORC("voreen.Python.PyVoreenQt", "Python environment not initialized"); }
void PlotPickingManager::activateTarget(std::string debugLabel) { if (rt_) { rt_->activateTarget(); rt_->setDebugLabel("ID target" + (debugLabel.empty() ? "" : " (" + debugLabel + ")")); } else LERRORC("voreen.plotpickingmanager", "No RenderTarget set!"); }
VoreenSettingsDialog::VoreenSettingsDialog(QWidget* parent) : QDialog(parent, Qt::Tool | Qt::Window) { setWindowTitle(tr("Voreen settings editor")); // vertical layout of the widget QVBoxLayout* widgetLayout = new QVBoxLayout(); setLayout(widgetLayout); // layout containing the property widgets QGridLayout* propertiesLayout = new QGridLayout(); // scrollarea surrounding the property widgets QWidget* scrollWidget = new QWidget(); scrollWidget->setLayout(propertiesLayout); QScrollArea* scrollArea = new QScrollArea(); scrollArea->setWidget(scrollWidget); scrollArea->setWidgetResizable(true); widgetLayout->addWidget(scrollArea); std::vector<voreen::Property*> properties = VoreenApplication::app()->getProperties(); // add property widgets to properties layout if (!VoreenApplication::app()) { LERRORC("voreen.qt.InputMappingDialog", "VoreenApplication not instantiated"); return; } for (size_t i=0; i<properties.size(); ++i) { Property* prop = properties.at(i); PropertyWidget* propWidget = VoreenApplication::app()->createPropertyWidget(prop); if (propWidget) prop->addWidget(propWidget); QPropertyWidget* qPropertyWidget = dynamic_cast<QPropertyWidget*>(propWidget); if (qPropertyWidget) { qPropertyWidget->hideLODControls(); qPropertyWidget->setMinimumWidth(250); CustomLabel* nameLabel = qPropertyWidget->getNameLabel(); int row = propertiesLayout->rowCount(); propertiesLayout->addWidget(nameLabel, row, 1); propertiesLayout->addWidget(qPropertyWidget, row, 2); } else { LERRORC("voreen.qt.VoreenSettingsDialog", "Unable to create property widget"); } } }
void Font::update(bool reloadFont) { if(reloadFont) { delete font_; font_ = 0; switch(fontType_) { case BitmapFont: font_ = new FTBitmapFont(fontName_.c_str()); break; case BufferFont: font_ = new FTBufferFont(fontName_.c_str()); break; case ExtrudeFont: font_ = new FTExtrudeFont(fontName_.c_str()); break; case OutlineFont: font_ = new FTOutlineFont(fontName_.c_str()); break; case PixmapFont: font_ = new FTPixmapFont(fontName_.c_str()); break; case PolygonFont: font_ = new FTPolygonFont(fontName_.c_str()); break; case TextureFont: font_ = new FTTextureFont(fontName_.c_str()); break; default: LWARNINGC("tgt.Font", "Unknown fontType. Defaulting to TextureFont."); font_ = new FTTextureFont(fontName_.c_str()); } } if (font_ && !font_->Error()) { font_->FaceSize(fontSize_); //delete simpleLayout_; //simpleLayout_ = 0; //simpleLayout_ = new FTSimpleLayout(); simpleLayout_->SetFont(font_); simpleLayout_->SetLineLength(lineWidth_); FTGL::TextAlignment hAlign = FTGL::ALIGN_LEFT; switch(hAlign_) { case Left: hAlign = FTGL::ALIGN_LEFT; break; case Center: hAlign = FTGL::ALIGN_CENTER; break; case Right: hAlign = FTGL::ALIGN_RIGHT; break; } simpleLayout_->SetAlignment(hAlign); } else { delete font_; font_ = 0; LERRORC("tgt.Font", "Font file could not be loaded: " << fontName_); } }
void IDManager::activateTarget(std::string debugLabel) { if (rt_) { rt_->activateTarget(); rt_->increaseNumUpdates(); rt_->setDebugLabel("ID target" + (debugLabel.empty() ? "" : " (" + debugLabel + ")")); } else LERRORC("voreen.idmanager", "No RenderTarget set!"); }
PlotBase& PlotBase::operator=(const PlotBase& rhs) { // prevent self assignment if (this == &rhs) return *this; std::string* newColumnLabels = 0; ColumnType* newColumnTypes = 0; // copy array data to new arrays // (exception safety: if anything fails the old data is still intact and the object in a valid state) try { int sum = rhs.keyColumnCount_ + rhs.dataColumnCount_; if (sum > 0) { newColumnLabels = new std::string[sum]; newColumnTypes = new ColumnType[sum]; } for (int i=0; i<sum; ++i) { newColumnLabels[i] = rhs.columnLabels_[i]; newColumnTypes[i] = rhs.columnTypes_[i]; } } catch (std::bad_alloc&) { // nothing has been destroyed yet, current state is valid LERRORC("PlotBase::operator=()", "bad_alloc occured, object was not changed!"); return *this; } catch (...) { // nothing has been destroyed yet, current state is valid LERRORC("PlotBase::operator=()", "unknown exception occured, object was not changed!"); return *this; } // everything here is exception safe: keyColumnCount_ = rhs.keyColumnCount_; dataColumnCount_ = rhs.dataColumnCount_; // exchange pointers via swap (exception safe) and delete old arrays std::swap(columnLabels_, newColumnLabels); std::swap(columnTypes_, newColumnTypes); delete [] newColumnLabels; delete [] newColumnTypes; return *this; }
TransFunc* TemplatePropertyTimeline<TransFunc*>::privateGetPropertyAt(float time) { TemplatePropertyTimelineState<TransFunc*>* tl = dynamic_cast<TemplatePropertyTimelineState<TransFunc*>* >(timeline_); if (tl) { TransFunc* func = const_cast<TransFunc*>(tl->getPropertyAt(time)); return func; } else { LERRORC("TemplatePropertyTimeline<TransFunc*>", "no timeline state"); return 0; } }
VolumeRepresentation* RepresentationConverterLoadFromDisk::convert(const VolumeRepresentation* source) const { tgtAssert(source, "null pointer passed"); const VolumeDisk* volumeDisk = dynamic_cast<const VolumeDisk*>(source); if (volumeDisk) { try { VolumeRAM* volumeRam = volumeDisk->loadVolume(); return volumeRam; } catch (tgt::Exception& e) { LERRORC("voreen.RepresentationConverterLoadFromDisk", "Unable to create VolumeRAM representation: " + std::string(e.what())); return 0; } } else { LERRORC("voreen.RepresentationConverterLoadFromDisk", "No VolumeDisk passed"); return 0; } }
PropertyKeyValue<TransFunc*>* PropertyKeyValue<TransFunc*>::clone() const { PropertyKeyValue<TransFunc*>* keyvalue = new PropertyKeyValue<TransFunc*>(); keyvalue->after_ = after_; keyvalue->before_ = before_; if (value_) keyvalue->value_ = value_->clone(); else LERRORC("voreen.PropertyKeyValue<TransFunc>", "No value"); keyvalue->time_ = time_; keyvalue->smooth_ = smooth_; return keyvalue; }
ProcessorWidget* CoreProcessorWidgetFactory::createWidget(Processor* processor) const { if (!VoreenApplicationQt::qtApp()) { LERRORC("voreen.CoreProcessorWidgetFactory", "VoreenApplicationQt not instantiated"); return 0; } QWidget* parent = VoreenApplicationQt::qtApp()->getMainWindow(); if (dynamic_cast<CanvasRenderer*>(processor)) return new CanvasRendererWidget(parent, static_cast<CanvasRenderer*>(processor)); else return 0; }
void LinkEvaluatorTransFuncId::eval(Property* src, Property* dst) throw (VoreenException) { TransFuncProperty* dstCast = static_cast<TransFuncProperty*>(dst); TransFuncProperty* srcCast = static_cast<TransFuncProperty*>(src); if(!srcCast->get()) { LERRORC("voreen.LinkEvaluatorTransFuncId", "src is has no TF"); return; } TransFunc* tf = srcCast->get()->clone(); dstCast->set(tf); }
VolumeRepresentation* RepresentationConverterUploadGL::convert(const VolumeRepresentation* source) const { const Volume* v = dynamic_cast<const Volume*>(source); if (!v) { //should have checked before... //LERROR("Failed to convert!"); return 0; } VolumeGL* vgl = 0; try { vgl = new VolumeGL(v); LGL_ERROR; } catch (VoreenException& e) { LERRORC("voreen.RepresentationConverterUploadGL", "Failed to create VolumeGL: " << e.what()); } catch (std::bad_alloc& /*e*/) { LERRORC("voreen.RepresentationConverterUploadGL", "Bad allocation during creation of VolumeGL"); } return vgl; }
ProcessorWidget* OpenCLProcessorWidgetFactory::createWidget(Processor* processor) const { if (!VoreenApplicationQt::qtApp()) { LERRORC("voreen.openclProcessorWidgetFactory", "VoreenApplicationQt not instantiated"); return 0; } QWidget* parent = VoreenApplicationQt::qtApp()->getMainWindow(); if (dynamic_cast<DynamicCLProcessor*>(processor)) return new DynamicOpenCLWidget(parent, static_cast<DynamicCLProcessor*>(processor)); return 0; }
void TemplatePropertyTimeline<Camera>::deserialize(XmlDeserializer& s) { s.deserialize("activeOnRendering", activeOnRendering_); PropertyOwner* propertyOwner = 0; s.deserialize("propertyOwner", propertyOwner); std::string propertyId; s.deserialize("propertyId", propertyId); if (propertyOwner) property_ = dynamic_cast<CameraProperty*>(propertyOwner->getProperty(propertyId)); else LERRORC("TemplatePropertyTimeline<Camera>", "deserialize(): no property owner"); s.deserialize("duration", duration_); s.deserialize("timeline", timeline_); }
ImageMappingInformation::ImageMappingInformation(const cgt::vec3& size, const cgt::vec3& offset, const cgt::vec3& voxelSize, const cgt::mat4& customTransformation /*= LinearMapping<float>::identity*/) : _size(size) , _offset(offset) , _voxelSize(voxelSize) , _customTransformation(customTransformation) { cgt::mat4 invTrafo; if (! _customTransformation.invert(invTrafo)) { LERRORC("CAMPVis.core.ImageMappingInformation", "Custom transformation is not invertable! Resetting to identity tranformation."); _customTransformation = cgt::mat4::identity; } updateMatrices(); }
col4 IDManager::getColorFromId(int id) { if(id < 0) return col4(0,0,0,0); if(id > 16777216) { LERRORC("voreen.IDManager", "id to big!"); return col4(0,0,0,0); } col4 c; c.b = id & 255; c.g = (id >> 8) & 255; c.r = (id >> 16) & 255; c.a = 255; return c; }
std::string OpenCLProperty::getProgramAsString(std::string filename) { //std::string completeFilename = ShdrMgr.completePath(filename); tgt::File* file = FileSys.open(filename); // check if file is open if (!file || !file->isOpen()) { LERRORC("voreen.openclproperty", "File not found: " << filename); delete file; return ""; } std::string s = file->getAsString(); file->close(); delete file; return s; }
void IDManager::increaseID() { if (currentID_.b == 255) { currentID_.b = 0; if (currentID_.g == 255) { currentID_.g = 0; if (currentID_.r == 255) { LERRORC("voreen.idmanager", "Out of ids..."); } else currentID_.r++; } else currentID_.g++; } else currentID_.b++; }
bool Property::isLinkableWith(const voreen::Property* dst) const{ if (!VoreenApplication::app()) { LERRORC("voreen.property", "VoreenApplication not instantiated"); return false; } const std::vector<voreen::VoreenModule*>& modules = VoreenApplication::app()->getModules(); for (size_t m=0; m<modules.size(); m++) { const std::vector<LinkEvaluatorFactory*>& factories = modules.at(m)->getLinkEvaluatorFactories(); for (size_t i=0; i<factories.size(); i++) { if (factories.at(i)->arePropertiesLinkable(this, dst)) return true; } } return false; }
ProcessorWidget* PlotProcessorWidgetFactory::createWidget(Processor* processor) const { if (!VoreenApplicationQt::qtApp()) { LERRORC("voreen.plotting.PlotProcessorWidgetFactory", "VoreenApplicationQt not instantiated"); return 0; } QWidget* parent = VoreenApplicationQt::qtApp()->getMainWindow(); if (dynamic_cast<PlotDataSelect*>(processor)) return new PlotDataSelectWidget(parent, static_cast<PlotDataSelect*>(processor)); else if (dynamic_cast<PlotDataGroup*>(processor)) return new PlotDataGroupWidget(parent, static_cast<PlotDataGroup*>(processor)); else if (dynamic_cast<PlotDataFitFunction*>(processor)) return new PlotDataFitFunctionWidget(parent, static_cast<PlotDataFitFunction*>(processor)); else if (dynamic_cast<PlotDataMerge*>(processor)) return new PlotDataMergeWidget(parent, static_cast<PlotDataMerge*>(processor)); return 0; }
void AnimationExportWidget::renderingStep(){ if (animation_ == 0) return; tgtAssert(canvas_, "No canvas"); if (currentFrame_ > duration_ / fpsFactor_){ endRendering(); } else { animation_->renderAt((float)currentFrame_*fpsFactor_/ fps_); #ifdef VRN_WITH_FFMPEG if ((renderState_== Recording) &&(painter_->getCanvasRenderer())) { if (canvas_->getSize() != tgt::ivec2(spinWidth_->value(), spinHeight_->value())) { canvas_->resize(spinWidth_->value(), spinHeight_->value()); canvas_->repaint(); } tgt::Texture* texture = painter_->getCanvasRenderer()->getImageColorTexture(); if (texture && texture->getDimensions().xy() == tgt::ivec2(spinWidth_->value(), spinHeight_->value())) { texture->downloadTexture(); ffmpegEncoder_.nextFrame(texture->getPixelData()); } else { LERRORC("voreenqt.AnimationExportWidget", "Frame texture could not be downloaded or dimensions do not match"); } } else { #endif // render frame to file char fn[1024]; sprintf(fn, "%s%05d%s", std::string(recordPathName_ + "/frame").c_str(), currentFrame_, ".png"); try { painter_->renderToSnapshot(fn, tgt::ivec2(spinWidth_->value(), spinHeight_->value())); } catch (...) {} #ifdef VRN_WITH_FFMPEG } #endif ++currentFrame_; } }
void LinkEvaluatorCameraLookId::eval(Property* src, Property* dst) throw (VoreenException) { bool camToProp = true; CameraProperty* camProp = dynamic_cast<CameraProperty*>(src); FloatVec3Property* vecProp = dynamic_cast<FloatVec3Property*>(dst); if(!camProp) { camToProp = false; camProp = dynamic_cast<CameraProperty*>(dst); vecProp = dynamic_cast<FloatVec3Property*>(src); } tgt::Camera cam = camProp->get(); if(camToProp) vecProp->set(cam.getLook()); else { if(length(vecProp->get()) == 0.f) { LERRORC("voreen.LinkEvaluatorCameraLookId", "Can not use 0 vector to set look vector of camera"); return; } cam.setFocus(cam.getPosition() + cam.getFocalLength() * normalize(vecProp->get())); camProp->set(cam); } }
void TemplatePropertyTimeline<TransFunc*>::setProperty(Property* p) { TemplateProperty<TransFunc*>* tp = dynamic_cast<TemplateProperty<TransFunc*>*>(p); if(tp) { property_ = tp; if(timeline_->getKeyValues().size() == 0) { delete timeline_; timeline_ = 0; TransFunc* func = property_->get(); if (func) func = func->clone(); else { LWARNINGC("", "warn 2"); func = new TransFunc1DKeys(); property_->set(func->clone()); } timeline_ = new TransFuncPropertyTimelineState(new PropertyKeyValue<TransFunc*>(func,0)); } } else { LERRORC("voreen.TemplatePropertyTimeline", "Property type mismatch!"); } }
VolumeHistogramIntensityGradient::VolumeHistogramIntensityGradient(const VolumeBase* volumeHandleGrad, const VolumeBase* volumeHandleIntensity, int bucketCounti, int bucketCountg, bool scale) : scaleFactor_(1.f) { const VolumeRAM* volumeGrad = volumeHandleGrad->getRepresentation<VolumeRAM>(); const VolumeRAM* volumeIntensity = volumeHandleIntensity->getRepresentation<VolumeRAM>(); if (dynamic_cast<const VolumeRAM_3xUInt8*>(volumeGrad)) { calcHG(static_cast<const VolumeRAM_3xUInt8*>(volumeGrad), volumeIntensity, bucketCounti, bucketCountg, scale); } else if (dynamic_cast<const VolumeRAM_4xUInt8*>(volumeGrad)) { calcHG(static_cast<const VolumeRAM_4xUInt8*>(volumeGrad), volumeIntensity, bucketCounti, bucketCountg, scale); } else if (dynamic_cast<const VolumeRAM_3xUInt16*>(volumeGrad)) { calcHG(static_cast<const VolumeRAM_3xUInt16*>(volumeGrad), volumeIntensity, bucketCounti, bucketCountg, scale); } else if (dynamic_cast<const VolumeRAM_4xUInt16*>(volumeGrad)) { calcHG(static_cast<const VolumeRAM_4xUInt16*>(volumeGrad), volumeIntensity, bucketCounti, bucketCountg, scale); } else { LERRORC("voreen.VolumeVolumeHistogramIntensityGradient", "VolumeVolumeHistogramIntensityGradient needs 24 or 32 bit DS as input!"); } }
void IDManager::deactivateTarget() { if (rt_) rt_->deactivateTarget(); else LERRORC("voreen.idmanager", "No RenderTarget set!"); }
cl::Device* OpenCLModule::getCLDevice() const { if (!device_) LERRORC("voreen.OpenCLModule", "No OpenCL device. Call initCL first!"); return device_; }