3 #ifndef OCTREE_CREATE_H
4 #define OCTREE_CREATE_H
10 #include "octree_node.h"
36 template<
int t_ColorFormat,
int t_Platform >
38 Synchronized::Heap< t_Platform >& heap,
39 Synchronized::TextureHeap< t_ColorFormat, t_Platform >& textureHeap,
40 unsigned int const depthRemaining,
49 bool const split = shape.Split( position, side );
50 bool const inside = ( shape.Inside( 0, center ) != 0 );
52 if ( ( depthRemaining > 0 ) && split ) {
54 result.children = heap.template Allocate< Node< t_ColorFormat, t_Platform > >( 8 );
56 double const sideChild = side / 2;
59 unsigned int index = 0;
60 positionChild[ 2 ] = position[ 2 ];
61 for (
unsigned int ii = 0; ii < 2; ++ii ) {
63 positionChild[ 1 ] = position[ 1 ];
64 for (
unsigned int jj = 0; jj < 2; ++jj ) {
66 positionChild[ 0 ] = position[ 0 ];
67 for (
unsigned int kk = 0; kk < 2; ++kk ) {
69 result.children.Assign( index, CreateNode( heap, textureHeap, depthRemaining - 1, positionChild, sideChild, shape ) );
71 positionChild[ 0 ] += sideChild;
74 positionChild[ 1 ] += sideChild;
76 positionChild[ 2 ] += sideChild;
80 if ( split || inside ) {
82 result.texture = textureHeap.Allocate( 2 );
84 double const textureSide = ( side / 4 );
87 unsigned int index = 0;
88 texturePosition[ 2 ] = position[ 2 ] + ( textureSide / 2 );
89 for (
unsigned int ii = 0; ii < 4; ++ii ) {
91 texturePosition[ 1 ] = position[ 1 ] + ( textureSide / 2 );
92 for (
unsigned int jj = 0; jj < 4; ++jj ) {
94 texturePosition[ 0 ] = position[ 0 ] + ( textureSide / 2 );
95 for (
unsigned int kk = 0; kk < 4; ++kk ) {
97 std::array< uint8_t, 3 > color;
98 switch( shape.Inside( 0, texturePosition ) ) {
102 color[ 0 ] = ( ( texturePosition[ 0 ] > 0 ) ? 0x00 : 0x80 );
103 color[ 1 ] = ( ( texturePosition[ 1 ] > 0 ) ? 0x00 : 0x80 );
104 color[ 2 ] = ( ( texturePosition[ 2 ] > 0 ) ? 0x00 : 0x80 );
106 uint8_t
const xxIndex =
static_cast< uint8_t
>( ( texturePosition[ 0 ] + 1 ) * 512 + 0.5 );
107 uint8_t
const yyIndex =
static_cast< uint8_t
>( ( texturePosition[ 1 ] + 1 ) * 512 + 0.5 );
108 uint8_t
const zzIndex =
static_cast< uint8_t
>( ( texturePosition[ 2 ] + 1 ) * 512 + 0.5 );
110 color[ 0 ] += ( ( yyIndex ^ zzIndex ) & 0x7f );
111 color[ 1 ] += ( ( xxIndex ^ zzIndex ) & 0x7f );
112 color[ 2 ] += ( ( xxIndex ^ yyIndex ) & 0x7f );
119 color[ 0 ] =
static_cast< uint8_t
>( std::max( 0.0, std::min( 1.0, ( texturePosition[ 0 ] + 0.1 ) / 0.2 ) ) * 0xef + 0x10 );
120 color[ 1 ] =
static_cast< uint8_t
>( std::max( 0.0, std::min( 1.0, ( texturePosition[ 1 ] + 0.1 ) / 0.2 ) ) * 0xff + 0x00 );
121 color[ 2 ] =
static_cast< uint8_t
>( std::max( 0.0, std::min( 1.0, ( texturePosition[ 2 ] + 0.1 ) / 0.2 ) ) * 0xef + 0x10 );
133 color[ 0 ] ^= ( ( ii & 1 ) << 4 );
134 color[ 1 ] ^= ( ( jj & 1 ) << 3 );
135 color[ 2 ] ^= ( ( kk & 1 ) << 4 );
142 color[ 0 ] = ( ( texturePosition[ 0 ] > 0 ) ? 0xc0 : 0x20 );
143 color[ 1 ] = ( ( texturePosition[ 1 ] > 0 ) ? 0xc0 : 0x20 );
144 color[ 2 ] = ( ( texturePosition[ 2 ] > 0 ) ? 0xc0 : 0x20 );
147 color[ 0 ] ^= ( ( ii & 1 ) << 5 );
148 color[ 1 ] ^= ( ( jj & 1 ) << 4 );
149 color[ 2 ] ^= ( ( kk & 1 ) << 5 );
164 assert( index < 64 );
165 result.texture.Assign( index, Color< t_ColorFormat >( color[ 0 ], color[ 1 ], color[ 2 ] ) );
168 texturePosition[ 0 ] += textureSide;
171 texturePosition[ 1 ] += textureSide;
174 texturePosition[ 2 ] += textureSide;
189 template<
int t_ColorFormat,
int t_Platform >
191 Synchronized::Heap< t_Platform >& heap,
192 Synchronized::TextureHeap< t_ColorFormat, t_Platform >& textureHeap,
194 unsigned int const depthRemaining,
203 bool const split = shape.Split( position, side );
204 bool const inside = ( shape.Inside( 0, center ) != 0 );
206 if ( ( depthRemaining > 0 ) && split ) {
208 if ( originalNode.children ) {
210 result.children = heap.template Allocate< Node< t_ColorFormat, t_Platform > >( 8 );
212 double const sideChild = side / 2;
215 unsigned int index = 0;
216 positionChild[ 2 ] = position[ 2 ];
217 for (
unsigned int ii = 0; ii < 2; ++ii ) {
219 positionChild[ 1 ] = position[ 1 ];
220 for (
unsigned int jj = 0; jj < 2; ++jj ) {
222 positionChild[ 0 ] = position[ 0 ];
223 for (
unsigned int kk = 0; kk < 2; ++kk ) {
225 result.children.Assign( index, SubtractNode( heap, textureHeap, originalNode.children[ index ], depthRemaining - 1, positionChild, sideChild, shape ) );
227 positionChild[ 0 ] += sideChild;
230 positionChild[ 1 ] += sideChild;
232 positionChild[ 2 ] += sideChild;
238 result.children = originalNode.children;
240 if ( originalNode.texture ) {
244 result.texture = textureHeap.Allocate( 2 );
246 double const textureSide = ( side / 4 );
249 unsigned int index = 0;
250 texturePosition[ 2 ] = position[ 2 ] + ( textureSide / 2 );
251 for (
unsigned int ii = 0; ii < 4; ++ii ) {
253 texturePosition[ 1 ] = position[ 1 ] + ( textureSide / 2 );
254 for (
unsigned int jj = 0; jj < 4; ++jj ) {
256 texturePosition[ 0 ] = position[ 0 ] + ( textureSide / 2 );
257 for (
unsigned int kk = 0; kk < 4; ++kk ) {
259 if ( ! shape.Inside( 0, texturePosition ) ) {
261 assert( index < 64 );
262 result.texture.Assign( index, originalNode.texture[ index ] );
266 texturePosition[ 0 ] += textureSide;
269 texturePosition[ 1 ] += textureSide;
272 texturePosition[ 2 ] += textureSide;
276 result.texture = originalNode.texture;
295 template<
int t_ColorFormat,
int t_Platform >
296 typename Synchronized::Heap< t_Platform >::template Pointer< Node< t_ColorFormat, t_Platform > >
const Create(
297 Synchronized::Heap< t_Platform >& heap,
298 Synchronized::TextureHeap< t_ColorFormat, t_Platform >& textureHeap,
299 unsigned int const logResolution = 7
304 {
Vector< double, 3 > center = { { 0.0, 0.0, 0.0 } }; shape.PushBall( 1, center, 1.0, 0.6 ); }
305 {
Vector< double, 3 > center = { { 0.0, 0.0, 0.0 } }; shape.PushBall( 0, center, 0.9, 0.6 ); }
306 {
Vector< double, 3 > center = { { 0.0, 0.0, 0.0 } }; shape.PushBall( 2, center, 0.1, 2.0 ); }
308 {
Vector< double, 3 > center = { { 0.00, 0.00, 0.97 } }; shape.PushBall( 3, center, 0.03, 2.0 ); }
309 {
Vector< double, 3 > center = { { 0.00, 0.00, -0.97 } }; shape.PushBall( 3, center, 0.03, 2.0 ); }
310 {
Vector< double, 3 > center = { { 0.00, 0.97, 0.00 } }; shape.PushBall( 3, center, 0.03, 2.0 ); }
311 {
Vector< double, 3 > center = { { 0.00, -0.97, 0.00 } }; shape.PushBall( 3, center, 0.03, 2.0 ); }
312 {
Vector< double, 3 > center = { { 0.97, 0.00, 0.00 } }; shape.PushBall( 3, center, 0.03, 2.0 ); }
313 {
Vector< double, 3 > center = { { -0.97, 0.00, 0.00 } }; shape.PushBall( 3, center, 0.03, 2.0 ); }
315 {
Vector< double, 3 > center = { { 0.3, 0.3, 0.3 } }; shape.PushBall( 4, center, 0.1, 4.0 ); }
316 {
Vector< double, 3 > center = { { 0.3, 0.3, -0.3 } }; shape.PushBall( 4, center, 0.1, 4.0 ); }
317 {
Vector< double, 3 > center = { { 0.3, -0.3, 0.3 } }; shape.PushBall( 4, center, 0.1, 4.0 ); }
318 {
Vector< double, 3 > center = { { 0.3, -0.3, -0.3 } }; shape.PushBall( 4, center, 0.1, 4.0 ); }
319 {
Vector< double, 3 > center = { { -0.3, 0.3, 0.3 } }; shape.PushBall( 4, center, 0.1, 4.0 ); }
320 {
Vector< double, 3 > center = { { -0.3, 0.3, -0.3 } }; shape.PushBall( 4, center, 0.1, 4.0 ); }
321 {
Vector< double, 3 > center = { { -0.3, -0.3, 0.3 } }; shape.PushBall( 4, center, 0.1, 4.0 ); }
322 {
Vector< double, 3 > center = { { -0.3, -0.3, -0.3 } }; shape.PushBall( 4, center, 0.1, 4.0 ); }
324 assert( logResolution > 0 );
328 typename Synchronized::Heap< t_Platform >::template Pointer< Node< t_ColorFormat, t_Platform > > pRoot = heap.template Allocate< Node< t_ColorFormat, t_Platform > >();
329 pRoot.Assign( CreateNode( heap, textureHeap, logResolution, position, 2, shape ) );
342 template<
int t_ColorFormat,
int t_Platform >
343 typename Synchronized::Heap< t_Platform >::template Pointer< Node< t_ColorFormat, t_Platform > >
const Subtract(
344 Synchronized::Heap< t_Platform >& heap,
345 Synchronized::TextureHeap< t_ColorFormat, t_Platform >& textureHeap,
350 unsigned int const logResolution = 7
355 shape.PushBall( 1, scaledCenter, radius, power );
359 typename Synchronized::Heap< t_Platform >::template Pointer< Node< t_ColorFormat, t_Platform > > pRoot = heap.template Allocate< Node< t_ColorFormat, t_Platform > >();
360 pRoot.Assign( SubtractNode( heap, textureHeap, *pOriginalRoot, logResolution, position, 2, shape ) );
373 #endif // OCTREE_CREATE_H