VolumeInterface Manual
A maxon::VolumeInterface is used to store and handle volume data. It is typically obtained from a VolumeObject ,见 VolumeObject Manual .
Volume information can be stored in a file:
// create VolumeObject VolumeObject * const volumeObj = VolumeObject::Alloc (); if (volumeObj == nullptr ) return maxon::OutOfMemoryError( MAXON_SOURCE_LOCATION );
// insert volume volumeObj-> SetVolume (volume);
The grid settings are accessed with:
// get volume const maxon::Volume volume = volumeObject-> GetVolume ();
// check grid if (volume.HasGrid()) { const maxon::String gridName = volume.GetGridName(); const GRIDCLASS gridClass = volume.GetGridClass(); DiagnosticOutput ( "@ (@)" , gridName, gridClass); }
The data stored in a volume is accessed with the maxon::GridIteratorInterface iterator:
// get volume const maxon::Volume volume = volumeObject-> GetVolume ();
// get matrix const maxon::Matrix transform = volume.GetGridTransform();
// create iterator maxon::GridIteratorRef<maxon::Float32, maxon::ITERATORTYPE::ON> iterator = maxon::GridIteratorRef<maxon::Float32, maxon::ITERATORTYPE::ON>::Create () iferr_return ; iterator.Init(volume) iferr_return ;
// iterate for (; iterator.IsNotAtEnd(); iterator.StepNext()) { // get value const Float32 value = iterator.GetValue(); // get coordinates const maxon::IntVector32 coord = iterator.GetCoords(); DiagnosticOutput ( "@: @" , coord, value);
// get world space coordinates 向量 pos; pos. x = coord. x ; pos. y = coord. y ; pos. z = coord. z ; pos = transform * pos; DiagnosticOutput ( "World space coordinates: @" , pos); }
The grid accessor can be used to both retrieve and set the volume data:
Volume data is accessed with:
// create VolumeObject VolumeObject * const volumeObj = VolumeObject::Alloc (); if (volumeObj == nullptr ) return maxon::OutOfMemoryError( MAXON_SOURCE_LOCATION ); doc-> InsertObject (volumeObj, nullptr , nullptr );
// create volume maxon::Volume volume = maxon::VolumeToolsInterface::CreateNewFloat32Volume (0.0) iferr_return ; volume.SetGridClass( GRIDCLASS :: FOG ) iferr_return ; volume.SetGridName("Example Grid"_s); const 向量 scaleFactor { 10.0 }; const maxon::Matrix scaleMatrix = MatrixScale (scaleFactor); volume.SetGridTransform(scaleMatrix) iferr_return ;
// create accessor maxon::GridAccessorRef<Float32> access = maxon::GridAccessorRef<Float32>::Create () iferr_return ; access.InitWithWriteAccess(volume, maxon :: VOLUMESAMPLER ::NEAREST) iferr_return ;
// set values in the shape of a helix Float offset = 0.0; const Float scale = 100.0; const Float scaleY = 10.0; while (offset < 50.0) { Float64 sin; Float64 cos; maxon::SinCos (offset, sin, cos); maxon::IntVector32 pos; pos. x = maxon::Int32 (sin * scale); pos. z = maxon::Int32 (cos * scale); pos. y = maxon::Int32 (offset * scaleY);
// set value access.SetValue(pos, 10.0) iferr_return ; offset = offset + 0.01; }
// insert volume volumeObj-> SetVolume (volume);