void VolumeCubify::process() { if (!enableProcessing_.get()) { outport_.setData(inport_.getData(), false); return; } const VolumeRAM* inputVolume = inport_.getData()->getRepresentation<VolumeRAM>(); VolumeRAM* outputVolume = 0; tgt::ivec3 oldims = inputVolume->getDimensions(); tgt::ivec3 newdims = tgt::ivec3(tgt::max(oldims)); tgt::ivec3 llf = (newdims - oldims) / 2; tgt::ivec3 urb = (newdims + oldims) / 2; if(dynamic_cast<const VolumeRAM_UInt8*>(inputVolume)) outputVolume = new VolumeRAM_UInt8(newdims); else if(dynamic_cast<const VolumeRAM_UInt16*>(inputVolume)) outputVolume = new VolumeRAM_UInt16(newdims); else LERROR("Unsupported value for getBitsStored()"); for (int voxel_z=0; voxel_z < newdims.z; voxel_z++) { for (int voxel_y=0; voxel_y < newdims.y; voxel_y++) { for (int voxel_x=0; voxel_x < newdims.x; voxel_x++) { tgt::ivec3 pos = tgt::ivec3(voxel_x, voxel_y, voxel_z); if(tgt::hor(tgt::lessThan(pos, llf)) || tgt::hor(tgt::greaterThanEqual(pos, urb))) outputVolume->setVoxelNormalized(0.f, pos); else { tgt::ivec3 oldPos = pos - llf; outputVolume->setVoxelNormalized(inputVolume->getVoxelNormalized(oldPos), pos); } } } } // assign computed volume to outport if (outputVolume) { Volume* h = new Volume(outputVolume, inport_.getData()); h->setOffset(h->getOffset() - (tgt::vec3(llf) * h->getSpacing())); outport_.setData(h); } else outport_.setData(0); }
void VolumeNoisifier::apply(){ if(inport_.hasData()){ Volume* vol = inport_.getData()->clone(); const VolumeRAM* vr = vol->getRepresentation<VolumeRAM>(); VolumeRAM* vrw = vol->getWritableRepresentation<VolumeRAM>(); size_t numVertices = vol->getNumVoxels(); float mxi = vr->maxNormalizedValue(), mni = vr->minNormalizedValue(); printf("Max before : %f | Min before : %f\n", mxi, mni); float mxia = 0, mnia = FLT_MAX; for(size_t i = 0; i < numVertices; ++i){ float val = vr->getVoxelNormalized(i); val += level_.get()*((mxi - mni)*((float)rand()/RAND_MAX) + mni); mxia = val > mxia ? val : mxia; mnia = val < mnia ? val : mnia; vrw->setVoxelNormalized(val, i); } printf("Max after : %f | Min after : %f\n", mxia, mnia); outport_.setData(vol); } }
void VolumeMasking::maskVolume() { tgtAssert(inport_.hasData(), "Inport has not data"); forceUpdate_ = false; const VolumeRAM* vol = inport_.getData()->getRepresentation<VolumeRAM>(); if (vol) { VolumeRAM* v = 0; v = vol->clone(); tgt::Texture* maskTexture = maskFunction_.get()->getTexture(); TransFunc1DKeys* tf = dynamic_cast<TransFunc1DKeys*>(maskFunction_.get()); maskTexture->downloadTexture(); const int maskTexDim = maskTexture->getDimensions().x; RealWorldMapping rwm = inport_.getData()->getRealWorldMapping(); // apply masking if (passedVoxelAction_.isSelected("maxIntensity")) { for (size_t i=0; i<v->getNumVoxels(); i++) { float intensity = vol->getVoxelNormalized(i); intensity = rwm.normalizedToRealWorld(intensity); intensity = tf->realWorldToNormalized(intensity); int index = static_cast<int>(intensity*(maskTexDim-1)); index = tgt::clamp(index, 0, maskTexDim-1); int alpha = maskTexture->texel< tgt::Vector4<uint8_t> >(static_cast<size_t>(index)).a; v->setVoxelNormalized(alpha == 0 ? 0.f : 1.f, i); //progressBar_->setProgress(static_cast<float>(i) / static_cast<float>(v->getNumVoxels())); } } else if (passedVoxelAction_.isSelected("passThrough")) { for (size_t i=0; i<v->getNumVoxels(); i++) { float intensity = vol->getVoxelNormalized(i); intensity = rwm.normalizedToRealWorld(intensity); intensity = tf->realWorldToNormalized(intensity); int index = static_cast<int>(intensity*(maskTexDim-1)); index = tgt::clamp(index, 0, maskTexDim-1); int alpha = maskTexture->texel< tgt::Vector4<uint8_t> >(static_cast<size_t>(index)).a; if (alpha == 0) v->setVoxelNormalized(0.f, i); } } else if (passedVoxelAction_.isSelected("alpha")) { for (size_t i=0; i<v->getNumVoxels(); i++) { float intensity = vol->getVoxelNormalized(i); intensity = rwm.normalizedToRealWorld(intensity); intensity = tf->realWorldToNormalized(intensity); int index = static_cast<int>(intensity*(maskTexDim-1)); index = tgt::clamp(index, 0, maskTexDim-1); int alpha = maskTexture->texel< tgt::Vector4<uint8_t> >(static_cast<size_t>(index)).a; v->setVoxelNormalized((float)alpha / 255.0f, i); } } else { LWARNING("Unknown voxel action: " << passedVoxelAction_.get()); } Volume* vh = new Volume(v, inport_.getData()); if (passedVoxelAction_.isSelected("alpha")) vh->setRealWorldMapping(RealWorldMapping()); outport_.setData(vh); } else { outport_.setData(0); } }