CFx SDK Documentation 2026 SP0
Loading...
Searching...
No Matches
LODAlgorithm.h
Go to the documentation of this file.
1
2// Copyright (C) 2002-2024, Open Design Alliance (the "Alliance").
3// All rights reserved.
4//
5// This software and its documentation and related materials are owned by
6// the Alliance. The software may only be incorporated into application
7// programs owned by members of the Alliance, subject to a signed
8// Membership Agreement and Supplemental Software License Agreement with the
9// Alliance. The structure and organization of this software are the valuable
10// trade secrets of the Alliance and its suppliers. The software is also
11// protected by copyright law and international treaty provisions. Application
12// programs incorporating this software must include the following statement
13// with their copyright notices:
14//
15// This application incorporates Open Design Alliance software pursuant to a license
16// agreement with Open Design Alliance.
17// Open Design Alliance Copyright (C) 2002-2024 by Open Design Alliance.
18// All rights reserved.
19//
20// By use of this software, its documentation or related materials, you
21// acknowledge and accept the above terms.
23
24#include <iostream>
25#include "OdPlatformStreamer.h"
26
27namespace LODAlgorithm {
28
29namespace Clustering {
30
31void compress(const OdUInt32& nPoints,
32 const OdUInt8& level,
33 const OdGeExtents3d& ext,
34 OdStreamBuf& origBuf,
35 OdStreamBuf& targetBuf,
36 const bool isLog = false)
37{
38 OdUInt8 mask = 0x80;
39 unsigned int byte = 0;
40 OdUInt32 bytesCnt = 0;
41 int comp = 0;
42
43 double min[3] = {ext.minPoint().x, ext.minPoint().y, ext.minPoint().z};
44 double max[3] = {ext.maxPoint().x, ext.maxPoint().y, ext.maxPoint().z};
45
46 if (isLog) {
47 printf("LOD Start compression\n");
48 printf("EXT MIN: %f %f %f\nEXT MAX: %f %f %f\n", min[0], min[1], min[2], max[0], max[1], max[2]);
49#if OD_SIZEOF_LONG == 4
50 printf("N points: %lu Level: %hhu\n", nPoints, level);
51#else
52 printf("N points: %u Level: %hhu\n", nPoints, level);
53#endif
54 }
55
56 OdUInt32 valCnt = nPoints * 3;
57 while(valCnt--) {
58 double value = OdPlatformStreamer::rdDouble(origBuf);
59
60 OdUInt32 clstrValue = static_cast<OdUInt32>(floor(((pow(2.0, level) - 1) / (max[comp] - min[comp])) * (value - min[comp]) + 0.5));
61
62 //calc component axis
63 comp = (comp >= 2) ? 0 : comp + 1;
64
65 if (isLog)
66 {
67#if OD_SIZEOF_LONG == 4
68 printf("v:%f n:%06lu ", value, clstrValue);
69#else
70 printf("v:%f n:%06u ", value, clstrValue);
71#endif
72 }
73
74 for (int i = level - 1; i >= 0; --i) {
75 unsigned int bit = clstrValue >> i & 1;
76 byte = OdUInt8(bit != 0 ? (byte|mask) : (byte & (~mask)));
77
78 //seek
79 mask >>= 1;
80 if(!mask)
81 {
82 mask = 0x80;
83 targetBuf.putByte(byte);
84 bytesCnt++;
85 byte = 0;
86 }
87 }
88 }
89
90 if(byte != 0)
91 targetBuf.putByte(byte);
92
93 if (isLog)
94 {
95#if OD_SIZEOF_LONG == 4
96 printf("End compression\nBytes written: %lu\n", ++bytesCnt);
97#else
98 printf("End compression\nBytes written: %u\n", ++bytesCnt);
99#endif
100 }
101}
102
103void decompress(const OdUInt32& nPoints,
104 const OdUInt8& level,
105 const OdGeExtents3d& ext,
106 OdStreamBuf& origBuf,
107 OdStreamBuf& targetBuf,
108 const bool isLog = false)
109{
110 double min[3] = {ext.minPoint().x, ext.minPoint().y, ext.minPoint().z};
111 double max[3] = {ext.maxPoint().x, ext.maxPoint().y, ext.maxPoint().z};
112
113 if (isLog) {
114 printf("LOD Start decompression\n");
115 printf("EXT MIN: %f %f %f\nEXT MAX: %f %f %f\n", min[0], min[1], min[2], max[0], max[1], max[2]);
116#if OD_SIZEOF_LONG == 4
117 printf("N points: %lu Level: %hhu\n", nPoints, level);
118#else
119 printf("N points: %u Level: %hhu\n", nPoints, level);
120#endif
121 }
122
123 unsigned int byte = origBuf.getByte();
124 OdUInt8 mask = 0x80;
125 OdUInt32 value = 0;
126 OdUInt8 comp = 0;
127 OdUInt8 bitShift = 7;
128 OdUInt32 bytesCnt = 1;
129
130 for (OdUInt32 i = 0; i < nPoints * 3; ++i) {
131
132 for (int j = level - 1; j >= 0; --j) {
133 unsigned int val = byte >> bitShift & 1;
134 value += val << j;
135 mask >>=1;
136 bitShift--;
137
138 if(!mask) {
139 mask = 0x80;
140 bitShift = 7;
141
142 if (i == nPoints * 3 - 1 && j == 0)
143 continue;
144
145 byte = origBuf.getByte();
146 bytesCnt++;
147 }
148 }
149
150 float newVal = static_cast<float>(((max[comp] - min[comp]) / pow(2.0, level)) * value + min[comp]);
151 if (isLog)
152 {
153#if OD_SIZEOF_LONG == 4
154 printf("v:%f n:%lu \t", newVal, value);
155#else
156 printf("v:%f n:%u \t", newVal, value);
157#endif
158 }
159
160 value = 0;
161 comp = (comp >= 2) ? 0 : comp + 1;
162 OdPlatformStreamer::wrFloat(targetBuf, newVal);
163 }
164
165 if (isLog)
166 {
167#if OD_SIZEOF_LONG == 4
168 printf("End compression\nBytes readed: %lu\n", bytesCnt);
169#else
170 printf("End compression\nBytes readed: %u\n", bytesCnt);
171#endif
172 }
173}
174
175}
176}
unsigned int OdUInt32
unsigned char OdUInt8
const OdGePoint3d & maxPoint() const
const OdGePoint3d & minPoint() const
static void wrFloat(OdStreamBuf &streamBuf, float value)
static double rdDouble(OdStreamBuf &streamBuf)
virtual OdUInt8 getByte()
virtual void putByte(OdUInt8 value)
GLint level
Definition gles2_ext.h:110
GLenum GLint GLuint mask
Definition gles2_ext.h:262
GLsizei const GLfloat * value
Definition gles2_ext.h:302
void decompress(const OdUInt32 &nPoints, const OdUInt8 &level, const OdGeExtents3d &ext, OdStreamBuf &origBuf, OdStreamBuf &targetBuf, const bool isLog=false)
void compress(const OdUInt32 &nPoints, const OdUInt8 &level, const OdGeExtents3d &ext, OdStreamBuf &origBuf, OdStreamBuf &targetBuf, const bool isLog=false)