History

changes after merge

vincent committed 13 years ago

Commit 56aac702 parents 081ebd5 60dc43061 files · +6546 −240Browse files

Showing the changes to interface/src/VoxelSystem.cpp (1 of 61 files). Show all

Unified · Split

interface/src/VoxelSystem.cpp+91−16
@@ -14,11 +14,12 @@ · 13 unmodified lines
1414 #include <iostream> // to load voxels from file
1515 #include <fstream> // to load voxels from file
1616 #include <SharedUtil.h>
17+#include <PacketHeaders.h>
1718 #include <OctalCode.h>
1819 #include <pthread.h>
1920 #include "VoxelSystem.h"
2021
21−const int MAX_VOXELS_PER_SYSTEM = 1500000; //250000;
22+const int MAX_VOXELS_PER_SYSTEM = 250000;
2223
2324 const int VERTICES_PER_VOXEL = 8;
2425 const int VERTEX_POINTS_PER_VOXEL = 3 * VERTICES_PER_VOXEL;
@@ -86,13 +87,69 @@ void VoxelSystem::createSphere(float r,float xc, float yc, float zc, float s, bo · 61 unmodified lines
8687 setupNewVoxelsForDrawing();
8788 }
8889
90+long int VoxelSystem::getVoxelsCreated() {
91+ return tree->voxelsCreated;
92+}
93+
94+long int VoxelSystem::getVoxelsCreatedRunningAverage() {
95+ return tree->voxelsCreatedStats.getRunningAverage();
96+}
97+
98+long int VoxelSystem::getVoxelsColored() {
99+ return tree->voxelsColored;
100+}
101+
102+long int VoxelSystem::getVoxelsColoredRunningAverage() {
103+ return tree->voxelsColoredStats.getRunningAverage();
104+}
105+
106+long int VoxelSystem::getVoxelsBytesRead() {
107+ return tree->voxelsBytesRead;
108+}
109+
110+long int VoxelSystem::getVoxelsBytesReadRunningAverage() {
111+ return tree->voxelsBytesReadStats.getRunningAverage();
112+}
113+
89114
90115 void VoxelSystem::parseData(void *data, int size) {
91− // output the bits received from the voxel server
116+
117+ unsigned char command = *(unsigned char*)data;
92118 unsigned char *voxelData = (unsigned char *) data + 1;
93119
94− // ask the VoxelTree to read the bitstream into the tree
95− tree->readBitstreamToTree(voxelData, size - 1);
120+ switch(command) {
121+ case PACKET_HEADER_VOXEL_DATA:
122+ // ask the VoxelTree to read the bitstream into the tree
123+ tree->readBitstreamToTree(voxelData, size - 1);
124+ break;
125+ case PACKET_HEADER_ERASE_VOXEL:
126+ // ask the tree to read the "remove" bitstream
127+ tree->processRemoveVoxelBitstream((unsigned char*)data,size);
128+ break;
129+ case PACKET_HEADER_Z_COMMAND:
130+
131+ // the Z command is a special command that allows the sender to send high level semantic
132+ // requests, like erase all, or add sphere scene, different receivers may handle these
133+ // messages differently
134+ char* packetData =(char*)data;
135+ char* command = &packetData[1]; // start of the command
136+ int commandLength = strlen(command); // commands are null terminated strings
137+ int totalLength = 1+commandLength+1;
138+
139+ printf("got Z message len(%d)= %s\n",size,command);
140+
141+ while (totalLength <= size) {
142+ if (0==strcmp(command,(char*)"erase all")) {
143+ printf("got Z message == erase all\n");
144+ tree->eraseAllVoxels();
145+ }
146+ if (0==strcmp(command,(char*)"add scene")) {
147+ printf("got Z message == add scene - NOT SUPPORTED ON INTERFACE\n");
148+ }
149+ totalLength += commandLength+1;
150+ }
151+ break;
152+ }
96153
97154 setupNewVoxelsForDrawing();
98155 }
@@ -128,12 +185,35 @@ int VoxelSystem::treeToArrays(VoxelNode *currentNode, float nodePosition[3]) { · 29 unmodified lines
128185
129186 float halfUnitForVoxel = powf(0.5, *currentNode->octalCode) * (0.5 * TREE_SCALE);
130187 glm::vec3 viewerPosition = viewerHead->getPos();
188+
189+ // XXXBHG - Note: It appears as if the X and Z coordinates of Head or Agent are flip-flopped relative to the
190+ // coords of the voxel space. This flip flop causes LOD behavior to be extremely odd. This is my temporary hack
191+ // to fix this behavior. To disable this swap, set swapXandZ to false.
192+ bool swapXandZ=true;
193+ float viewerX = swapXandZ ? viewerPosition[2] : viewerPosition[0];
194+ float viewerZ = swapXandZ ? viewerPosition[0] : viewerPosition[2];
195+
196+ // debugging code.
197+ //printf("treeToArrays() halfUnitForVoxel=%f\n",halfUnitForVoxel);
198+ //printf("treeToArrays() viewerPosition {x,y,z or [0],[1],[2]} ={%f,%f,%f}\n",
199+ // viewerPosition[0],viewerPosition[1],viewerPosition[2]);
200+ //printf("treeToArrays() nodePosition {x,y,z or [0],[1],[2]} = {%f,%f,%f}\n",
201+ // nodePosition[0],nodePosition[1],nodePosition[2]);
202+ //float* vertices = firstVertexForCode(currentNode->octalCode);
203+ //printf("treeToArrays() firstVerticesForCode(currentNode->octalCode)={x,y,z or [0],[1],[2]} = {%f,%f,%f}\n",
204+ // vertices[0],vertices[1],vertices[2]);
205+ //delete []vertices;
131206
132− float distanceToVoxelCenter = sqrtf(powf(viewerPosition[0] - nodePosition[0] - halfUnitForVoxel, 2) +
207+ float distanceToVoxelCenter = sqrtf(powf(viewerX - nodePosition[0] - halfUnitForVoxel, 2) +
133208 powf(viewerPosition[1] - nodePosition[1] - halfUnitForVoxel, 2) +
134− powf(viewerPosition[2] - nodePosition[2] - halfUnitForVoxel, 2));
135−
136− if (distanceToVoxelCenter < boundaryDistanceForRenderLevel(*currentNode->octalCode + 1)) {
209+ powf(viewerZ - nodePosition[2] - halfUnitForVoxel, 2));
210+
211+ int boundaryPosition = boundaryDistanceForRenderLevel(*currentNode->octalCode + 1);
212+ //printf("treeToArrays() distanceToVoxelCenter=%f boundaryPosition=%d\n",distanceToVoxelCenter,boundaryPosition);
213+
214+ bool alwaysDraw = false; // XXXBHG - temporary debug code. Flip this to true to disable LOD blurring
215+
216+ if (alwaysDraw || distanceToVoxelCenter < boundaryPosition) {
137217 for (int i = 0; i < 8; i++) {
138218 // check if there is a child here
139219 if (currentNode->children[i] != NULL) {
@@ -150,8 +230,6 @@ int VoxelSystem::treeToArrays(VoxelNode *currentNode, float nodePosition[3]) { · 10 unmodified lines
150230 childNodePosition[j] -= (powf(0.5, *currentNode->children[i]->octalCode) * TREE_SCALE);
151231 }
152232 }
153−
154−
155233 voxelsAdded += treeToArrays(currentNode->children[i], childNodePosition);
156234 }
157235 }
@@ -189,11 +267,11 @@ VoxelSystem* VoxelSystem::clone() const { · 31 unmodified lines
189267
190268 void VoxelSystem::init() {
191269 // prep the data structures for incoming voxel data
192− writeVerticesArray = new GLfloat[VERTEX_POINTS_PER_VOXEL * MAX_VOXELS_PER_SYSTEM];
193− readVerticesArray = new GLfloat[VERTEX_POINTS_PER_VOXEL * MAX_VOXELS_PER_SYSTEM];
270+ writeVerticesEndPointer = writeVerticesArray = new GLfloat[VERTEX_POINTS_PER_VOXEL * MAX_VOXELS_PER_SYSTEM];
271+ readVerticesEndPointer = readVerticesArray = new GLfloat[VERTEX_POINTS_PER_VOXEL * MAX_VOXELS_PER_SYSTEM];
194272 writeColorsArray = new GLubyte[VERTEX_POINTS_PER_VOXEL * MAX_VOXELS_PER_SYSTEM];
195273 readColorsArray = new GLubyte[VERTEX_POINTS_PER_VOXEL * MAX_VOXELS_PER_SYSTEM];
196−
274+
197275 GLuint *indicesArray = new GLuint[INDICES_PER_VOXEL * MAX_VOXELS_PER_SYSTEM];
198276
199277 // populate the indicesArray
@@ -235,18 +313,15 @@ void VoxelSystem::render() { · 35 unmodified lines
235313
236314 glPushMatrix();
237315
238−
239316 if (readVerticesEndPointer != readVerticesArray) {
240317 // try to lock on the buffer write
241318 // just avoid pulling new data if it is currently being written
242319 if (pthread_mutex_trylock(&bufferWriteLock) == 0) {
243320
244321 glBindBuffer(GL_ARRAY_BUFFER, vboVerticesID);
245− glBufferData(GL_ARRAY_BUFFER, VERTEX_POINTS_PER_VOXEL * sizeof(GLfloat) * MAX_VOXELS_PER_SYSTEM, NULL, GL_DYNAMIC_DRAW);
246322 glBufferSubData(GL_ARRAY_BUFFER, 0, (readVerticesEndPointer - readVerticesArray) * sizeof(GLfloat), readVerticesArray);
247323
248324 glBindBuffer(GL_ARRAY_BUFFER, vboColorsID);
249− glBufferData(GL_ARRAY_BUFFER, VERTEX_POINTS_PER_VOXEL * sizeof(GLubyte) * MAX_VOXELS_PER_SYSTEM, NULL, GL_DYNAMIC_DRAW);
250325 glBufferSubData(GL_ARRAY_BUFFER, 0, (readVerticesEndPointer - readVerticesArray) * sizeof(GLubyte), readColorsArray);
251326
252327 readVerticesEndPointer = readVerticesArray;