Commit 5c739225 authored by Christian Schulte zu Berge's avatar Christian Schulte zu Berge
Browse files

Moved ScopedTypedData<T> directly into campvis namespace to avoid nested class

parent 536666b4
......@@ -97,7 +97,7 @@ namespace campvis {
glViewport(0, 0, size.x, size.y);
// try get Data
DataContainer::ScopedTypedData<RenderData> rd(_pipeline->getDataContainer(), _pipeline->getRenderTargetID());
ScopedTypedData<RenderData> rd(_pipeline->getDataContainer(), _pipeline->getRenderTargetID());
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if (rd != 0) {
// activate shader
......
......@@ -31,6 +31,7 @@
#define ABSTRACTDATA_H__
#include "tgt/bounds.h"
#include "core/datastructures/scopedtypeddata.h" // not directly needed here but by many classes including AbstractData
#include "core/tools/referencecounted.h"
namespace campvis {
......@@ -52,6 +53,7 @@ namespace campvis {
virtual tgt::Bounds getWorldBounds() const = 0;
};
// ================================================================================================
/**
* Abstract base class for data handled by a DataHandle and stored in a DataContainer.
......
......@@ -57,65 +57,6 @@ namespace campvis {
*/
class DataContainer {
public:
/**
* Proxy class for scoped strongly-typed access to the data of a DataContainer.
* From the outside DataContainer::ScopedTypedData<T> behaves exactly like a const T*, but internally it preserves the
* reference counting of a DataHandle. Use this class when you want temporary access to a strongly-typed
* data item in a DataContainer but don't want to to the dynamic_cast yourself.
*
* \tparam T Base class of the DataHandle data to test for
*/
template<typename T>
struct ScopedTypedData {
/**
* Creates a new DataHandle to the data item with the key \a name in \a dc, that behaves like a T*.
* \param dc DataContainer to grab data from
* \param name Key of the DataHandle to search for
*/
ScopedTypedData(const DataContainer& dc, const std::string& name)
: dh(dc.getData(name))
, data(0)
{
if (dh.getData() != 0) {
data = dynamic_cast<const T*>(dh.getData());
}
};
/**
* Implicit conversion operator to const T*.
* \return The data in the DataHandle, may be 0 when no DataHandle was found, or the data is of the wrong type.
*/
operator const T*() {
return data;
}
/**
* Implicit arrow operator to const T*.
* \return The data in the DataHandle, may be 0 when no DataHandle was found, or the data is of the wrong type.
*/
const T* operator->() const {
return data;
}
/**
* Gets the DataHandle.
* \return dh
*/
const DataHandle& getDataHandle() const {
return dh;
}
private:
/// Not copy-constructable
ScopedTypedData(const ScopedTypedData& rhs);
/// Not assignable
ScopedTypedData& operator=(const ScopedTypedData& rhs);
DataHandle dh; ///< DataHandle
const T* data; ///< strongly-typed pointer to data, may be 0
};
/**
* Creates a new empty DataContainer
*/
......
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universität München
// Boltzmannstr. 3, 85748 Garching b. München, Germany
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// The licensing of this softare is not yet resolved. Until then, redistribution in source or
// binary forms outside the CAMP chair is not permitted, unless explicitly stated in legal form.
// However, the names of the original authors and the above copyright notice must retain in its
// original state in any case.
//
// Legal disclaimer provided by the BSD license:
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ================================================================================================
#ifndef SCOPEDTYPEDDATA_H__
#define SCOPEDTYPEDDATA_H__
#include "core/datastructures/datacontainer.h"
namespace campvis {
/**
* Proxy class for scoped strongly-typed access to the data of a DataContainer.
* From the outside ScopedTypedData<T> behaves exactly like a const T*, but internally it preserves the
* reference counting of a DataHandle. Use this class when you want temporary access to a strongly-typed
* data item in a DataContainer but don't want to to the dynamic_cast yourself.
*
* \tparam T Base class of the DataHandle data to test for
*/
template<typename T>
struct ScopedTypedData {
/**
* Creates a new DataHandle to the data item with the key \a name in \a dc, that behaves like a T*.
* \param dc DataContainer to grab data from
* \param name Key of the DataHandle to search for
*/
ScopedTypedData(const DataContainer& dc, const std::string& name)
: dh(dc.getData(name))
, data(0)
{
if (dh.getData() != 0) {
data = dynamic_cast<const T*>(dh.getData());
}
};
/**
* Implicit conversion operator to const T*.
* \return The data in the DataHandle, may be 0 when no DataHandle was found, or the data is of the wrong type.
*/
operator const T*() {
return data;
}
/**
* Implicit arrow operator to const T*.
* \return The data in the DataHandle, may be 0 when no DataHandle was found, or the data is of the wrong type.
*/
const T* operator->() const {
return data;
}
/**
* Gets the DataHandle.
* \return dh
*/
const DataHandle& getDataHandle() const {
return dh;
}
private:
/// Not copy-constructable
ScopedTypedData(const ScopedTypedData& rhs);
/// Not assignable
ScopedTypedData& operator=(const ScopedTypedData& rhs);
DataHandle dh; ///< DataHandle
const T* data; ///< strongly-typed pointer to data, may be 0
};
}
#endif // SCOPEDTYPEDDATA_H__
\ No newline at end of file
......@@ -60,7 +60,7 @@ namespace campvis {
if (_applyMask.getValue()) {
shader->setUniform("_maskColor", _maskColor.getValue());
_maskImage = new DataContainer::ScopedTypedData<RenderData>(dataContainer, _maskID.getValue());
_maskImage = new ScopedTypedData<RenderData>(dataContainer, _maskID.getValue());
if (*_maskImage != 0) {
(*_maskImage)->bindColorTexture(shader, *_texUnit, "_maskImage", "_maskTexParams");
}
......
......@@ -59,7 +59,7 @@ namespace campvis {
Vec4Property _maskColor; ///< Mask color
tgt::TextureUnit* _texUnit;
DataContainer::ScopedTypedData<RenderData>* _maskImage;
ScopedTypedData<RenderData>* _maskImage;
};
}
......
......@@ -85,8 +85,8 @@ namespace campvis {
void RaycastingProcessor::process(DataContainer& data) {
ImageRepresentationGL::ScopedRepresentation img(data, p_sourceImageID.getValue());
DataContainer::ScopedTypedData<RenderData> entryPoints(data, p_entryImageID.getValue());
DataContainer::ScopedTypedData<RenderData> exitPoints(data, p_exitImageID.getValue());
ScopedTypedData<RenderData> entryPoints(data, p_entryImageID.getValue());
ScopedTypedData<RenderData> exitPoints(data, p_exitImageID.getValue());
if (img != 0 && entryPoints != 0 && exitPoints != 0) {
if (img->getDimensionality() == 3) {
......
......@@ -31,6 +31,7 @@
namespace campvis {
const std::string CameraProperty::loggerCat_ = "CAMPVis.core.datastructures.CameraProperty";
CameraProperty::CameraProperty(const std::string& name, const std::string& title, tgt::Camera cam /*= tgt::Camera()*/, int invalidationLevel /*= AbstractProcessor::INVALID_RESULT*/)
......
......@@ -235,7 +235,7 @@ namespace campvis {
void AdvancedUsVis::onProcessorValidated(AbstractProcessor* processor) {
if (processor = &_usReader) {
// convert data
DataContainer::ScopedTypedData<ImageData> img(*_data, _usReader.p_targetImageID.getValue());
ScopedTypedData<ImageData> img(*_data, _usReader.p_targetImageID.getValue());
if (img != 0) {
_trackballEH->reinitializeCamera(img);
}
......
......@@ -173,7 +173,7 @@ namespace campvis {
void CmBatchGeneration::save(int path, const std::string& basePath) {
// get result
DataContainer::ScopedTypedData<RenderData> rd(*_data, _usFusion.p_targetImageID.getValue());
ScopedTypedData<RenderData> rd(*_data, _usFusion.p_targetImageID.getValue());
const ImageRepresentationGL* rep = rd->getColorTexture()->getRepresentation<ImageRepresentationGL>(false);
if (rep != 0) {
#ifdef CAMPVIS_HAS_MODULE_DEVIL
......
......@@ -162,7 +162,7 @@ namespace campvis {
}
void AdvancedUsFusion::updateProperties(DataContainer dc) {
DataContainer::ScopedTypedData<ImageData> img(dc, p_usImageId.getValue());
ScopedTypedData<ImageData> img(dc, p_usImageId.getValue());
p_transferFunction.getTF()->setImageHandle(img.getDataHandle());
const tgt::svec3& imgSize = img->getSize();
......
......@@ -154,7 +154,7 @@ namespace campvis {
void Columbia1::onProcessorValidated(AbstractProcessor* processor) {
if (processor == &_imageSplitter) {
// update camera
DataContainer::ScopedTypedData<ImageData> img(*_data, _imageSplitter.p_outputID.getValue());
ScopedTypedData<ImageData> img(*_data, _imageSplitter.p_outputID.getValue());
if (img != 0) {
_trackballEH->reinitializeCamera(img);
}
......
......@@ -81,7 +81,7 @@ namespace campvis {
}
void GeometryStrainRenderer::process(DataContainer& data) {
DataContainer::ScopedTypedData<GeometryData> proxyGeometry(data, p_geometryID.getValue());
ScopedTypedData<GeometryData> proxyGeometry(data, p_geometryID.getValue());
ImageRepresentationGL::ScopedRepresentation strainData(data, p_strainId.getValue());
if (proxyGeometry != 0 && strainData != 0 && _shader != 0) {
......
......@@ -50,7 +50,7 @@ namespace campvis {
}
void ImageSeriesSplitter::process(DataContainer& data) {
DataContainer::ScopedTypedData<ImageSeries> series(data, p_inputID.getValue());
ScopedTypedData<ImageSeries> series(data, p_inputID.getValue());
if (series != 0) {
if (hasInvalidProperties()) {
p_imageIndex.setMaxValue(static_cast<int>(series->getNumImages()));
......
......@@ -98,7 +98,7 @@ namespace campvis {
validate(INVALID_SHADER);
}
DataContainer::ScopedTypedData<FiberData> strainData(data, p_strainId.getValue());
ScopedTypedData<FiberData> strainData(data, p_strainId.getValue());
if (strainData != 0 && _shader != 0) {
const tgt::Camera& camera = p_camera.getValue();
......
......@@ -149,8 +149,8 @@ namespace campvis {
return;
ImageRepresentationLocal::ScopedRepresentation img(data, _sourceImageID.getValue());
DataContainer::ScopedTypedData<RenderData> entryPoints(data, _entryImageID.getValue());
DataContainer::ScopedTypedData<RenderData> exitPoints(data, _exitImageID.getValue());
ScopedTypedData<RenderData> entryPoints(data, _entryImageID.getValue());
ScopedTypedData<RenderData> exitPoints(data, _exitImageID.getValue());
if (img != 0 && entryPoints != 0 && exitPoints != 0) {
if (img->getDimensionality() == 3) {
......
......@@ -136,7 +136,7 @@ namespace campvis {
}
void TrackedUsSweepFrameRenderer3D::process(DataContainer& data) {
DataContainer::ScopedTypedData< TrackedUsFileIoData > fio(data, p_sourceImageID.getValue());
ScopedTypedData< TrackedUsFileIoData > fio(data, p_sourceImageID.getValue());
if (fio != 0) {
if (_currentSweep != 0) {
......@@ -225,7 +225,7 @@ namespace campvis {
}
void TrackedUsSweepFrameRenderer3D::updateProperties(DataContainer& dc) {
DataContainer::ScopedTypedData<TrackedUsFileIoData> data(dc, p_sourceImageID.getValue());
ScopedTypedData<TrackedUsFileIoData> data(dc, p_sourceImageID.getValue());
if (data != 0) {
TrackedUSFileIO* fio = const_cast<TrackedUSFileIO*>(data->getData());
const TrackedUSFileXMLHeader::TrackedUSFileStudy *study = fio->getStudyHeader(0);
......
......@@ -153,7 +153,7 @@ namespace campvis {
void DVRVis::onProcessorValidated(AbstractProcessor* processor) {
if (processor == &_imageReader) {
// update camera
DataContainer::ScopedTypedData<ImageData> img(*_data, _imageReader.p_targetImageID.getValue());
ScopedTypedData<ImageData> img(*_data, _imageReader.p_targetImageID.getValue());
if (img != 0) {
_trackballEH->reinitializeCamera(img);
}
......
......@@ -94,7 +94,7 @@ namespace campvis {
void SliceVis::onProcessorValidated(AbstractProcessor* processor) {
if (processor == &_imageReader) {
DataContainer::ScopedTypedData<ImageData> img(*_data, _imageReader.p_targetImageID.getValue());
ScopedTypedData<ImageData> img(*_data, _imageReader.p_targetImageID.getValue());
if (img != 0) {
_sliceExtractor.p_transferFunction.getTF()->setImageHandle(img.getDataHandle());
}
......
......@@ -87,7 +87,7 @@ namespace campvis {
void VolumeRendererDemo::onProcessorValidated(AbstractProcessor* processor) {
if (processor == &_imageReader) {
// update camera
DataContainer::ScopedTypedData<ImageData> img(*_data, _imageReader.p_targetImageID.getValue());
ScopedTypedData<ImageData> img(*_data, _imageReader.p_targetImageID.getValue());
if (img != 0) {
_trackballEH->reinitializeCamera(img);
}
......
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