inline
void
VolumeRenderingSampler<Cartesian<ScalarParam,3,ValueParam> >::sample(
    const ScalarExtractorParam& scalarExtractor,
    VoxelParam* voxels,
    const ptrdiff_t voxelStrides[3],
    Comm::MulticastPipe* pipe,
    float percentageScale,
    float percentageOffset,
    Visualization::Abstract::Algorithm* algorithm) const
{
    typedef typename ScalarExtractorParam::Scalar VScalar;
    typedef VoxelParam Voxel;

    /* Determine the data set's value range: */
    VScalar minValue,maxValue;
    typename DataSet::VertexIterator vIt=dataSet.beginVertices();
    minValue=maxValue=vIt->getValue(scalarExtractor);
    for(++vIt; vIt!=dataSet.endVertices(); ++vIt)
    {
        VScalar value=vIt->getValue(scalarExtractor);
        if(minValue>value)
            minValue=value;
        if(maxValue<value)
            maxValue=value;
    }

    typename DataSet::Index index;
    Voxel* vPtr0=voxels;
    for(index[0]=0; index[0]<dataSet.getNumVertices()[0]; ++index[0],vPtr0+=voxelStrides[0])
    {
        Voxel* vPtr1=vPtr0;
        for(index[1]=0; index[1]<dataSet.getNumVertices()[1]; ++index[1],vPtr1+=voxelStrides[1])
        {
            Voxel* vPtr2=vPtr1;
            for(index[2]=0; index[2]<dataSet.getNumVertices()[2]; ++index[2],vPtr2+=voxelStrides[2])
            {
                /* Get the vertex' scalar value: */
                VScalar value=scalarExtractor.getValue(dataSet.getVertexValue(index));

                /* Convert the value to unsigned char: */
                *vPtr2=Voxel((value-minValue)*VScalar(255)/(maxValue-minValue)+VScalar(0.5));
            }
        }

        /* Update the busy dialog: */
        algorithm->callBusyFunction(float(index[0]+1)*percentageScale/float(dataSet.getNumVertices()[0])+percentageOffset);
    }
}
inline
SliceVolumeRenderer<Cartesian<ScalarParam,3,ValueParam>,ScalarExtractorParam>::SliceVolumeRenderer(
	const typename SliceVolumeRenderer<Cartesian<ScalarParam,3,ValueParam>,ScalarExtractorParam>::DataSet* sDataSet,
	const typename SliceVolumeRenderer<Cartesian<ScalarParam,3,ValueParam>,ScalarExtractorParam>::ScalarExtractor& sScalarExtractor,
	const GLColorMap* sColorMap,
	Comm::MulticastPipe* sPipe)
	:dataSet(sDataSet),
	 scalarExtractor(sScalarExtractor),
	 colorMap(sColorMap),
	 renderer(0),
	 transparencyGamma(1.0f)
	{
	/* Determine the data set's value range: */
	VScalar minValue,maxValue;
	typename DataSet::VertexIterator vIt=dataSet->beginVertices();
	minValue=maxValue=vIt->getValue(scalarExtractor);
	for(++vIt;vIt!=dataSet->endVertices();++vIt)
		{
		VScalar value=vIt->getValue(scalarExtractor);
		if(minValue>value)
			minValue=value;
		else if(maxValue<value)
			maxValue=value;
		}
	
	/* Create a palette renderer: */
	renderer=new PaletteRenderer;
	
	/* Create a voxel block: */
	int size[3];
	for(int i=0;i<3;++i)
		size[i]=dataSet->getNumVertices()[i];
	PaletteRenderer::Voxel* voxels;
	int increments[3];
	voxels=renderer->createVoxelBlock(size,0,PaletteRenderer::VERTEX_CENTERED,increments);
	
	/* Upload the data set's scalar values into the voxel block: */
	for(typename DataSet::Index index(0);index[0]<dataSet->getNumVertices()[0];index.preInc(dataSet->getNumVertices()))
		{
		/* Get the vertex' scalar value: */
		VScalar value=scalarExtractor.getValue(dataSet->getVertexValue(index));
		
		/* Convert the value to unsigned char: */
		PaletteRenderer::Voxel& voxel=voxels[index[0]*increments[0]+index[1]*increments[1]+index[2]*increments[2]];
		voxel=PaletteRenderer::Voxel(Math::floor((value-minValue)*VScalar(255)/(maxValue-minValue)+VScalar(0.5)));
		}
	renderer->finishVoxelBlock();
	
	/* Set the renderer's model space position and size: */
	renderer->setPosition(dataSet->getDomainBox().getOrigin(),dataSet->getDomainBox().getSize());
	
	/* Initialize volume renderer settings: */
	// renderer->setUseNPOTDTextures(true);
	renderer->setRenderingMode(PaletteRenderer::VIEW_PERPENDICULAR);
	renderer->setInterpolationMode(PaletteRenderer::LINEAR);
	renderer->setTextureFunction(PaletteRenderer::REPLACE);
	renderer->setSliceFactor(Scalar(2.0));
	renderer->setAutosaveGLState(true);
	renderer->setTextureCaching(true);
	renderer->setSharePalette(false);
	}