History

Added false colorization by voxel server source - switched readBitstreamToTree() to take params struct for future expansion - switched readNodeData() to take params for future expansion - added sourceID to VoxelNode - fixed false colorize routines to correctly redraw by marking tree as dirty

ZappoMan committed 13 years ago

Commit c7e3fe51 parent 620fe129 files · +165 −30Browse files

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

Unified · Split

interface/src/VoxelSystem.cpp+93−2
@@ -23,6 +23,8 @@ · 22 unmodified lines
2323 #include <PacketHeaders.h>
2424 #include <PerfStat.h>
2525 #include <SharedUtil.h>
26+#include <NodeList.h>
27+#include <NodeTypes.h>
2628
2729 #include "Application.h"
2830 #include "CoverageMap.h"
@@ -61,6 +63,8 @@ VoxelSystem::VoxelSystem(float treeScale, int maxVoxels) : · 32 unmodified lines
6163
6264 VoxelNode::addDeleteHook(this);
6365 _abandonedVBOSlots = 0;
66+ _falseColorizeBySource = false;
67+ _dataSourceID = UNKNOWN_NODE_ID;
6468 }
6569
6670 void VoxelSystem::nodeDeleted(VoxelNode* node) {
@@ -153,13 +157,15 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) { · 86 unmodified lines
153157 case PACKET_TYPE_VOXEL_DATA: {
154158 PerformanceWarning warn(_renderWarningsOn, "readBitstreamToTree()");
155159 // ask the VoxelTree to read the bitstream into the tree
156− _tree->readBitstreamToTree(voxelData, numBytes - numBytesPacketHeader, WANT_COLOR, WANT_EXISTS_BITS);
160+ ReadBitstreamToTreeParams args(WANT_COLOR, WANT_EXISTS_BITS, NULL, getDataSourceID());
161+ _tree->readBitstreamToTree(voxelData, numBytes - numBytesPacketHeader, args);
157162 }
158163 break;
159164 case PACKET_TYPE_VOXEL_DATA_MONOCHROME: {
160165 PerformanceWarning warn(_renderWarningsOn, "readBitstreamToTree()");
161166 // ask the VoxelTree to read the MONOCHROME bitstream into the tree
162− _tree->readBitstreamToTree(voxelData, numBytes - numBytesPacketHeader, NO_COLOR, WANT_EXISTS_BITS);
167+ ReadBitstreamToTreeParams args(NO_COLOR, WANT_EXISTS_BITS, NULL, getDataSourceID());
168+ _tree->readBitstreamToTree(voxelData, numBytes - numBytesPacketHeader, args);
163169 }
164170 break;
165171 case PACKET_TYPE_Z_COMMAND:
@@ -747,6 +753,7 @@ void VoxelSystem::randomizeVoxelColors() { · 581 unmodified lines
747753 _nodeCount = 0;
748754 _tree->recurseTreeWithOperation(randomColorOperation);
749755 qDebug("setting randomized true color for %d nodes\n", _nodeCount);
756+ _tree->setDirtyBit();
750757 setupNewVoxelsForDrawing();
751758 }
752759
@@ -761,6 +768,7 @@ void VoxelSystem::falseColorizeRandom() { · 8 unmodified lines
761768 _nodeCount = 0;
762769 _tree->recurseTreeWithOperation(falseColorizeRandomOperation);
763770 qDebug("setting randomized false color for %d nodes\n", _nodeCount);
771+ _tree->setDirtyBit();
764772 setupNewVoxelsForDrawing();
765773 }
766774
@@ -775,6 +783,7 @@ void VoxelSystem::trueColorize() { · 8 unmodified lines
775783 _nodeCount = 0;
776784 _tree->recurseTreeWithOperation(trueColorizeOperation);
777785 qDebug("setting true color for %d nodes\n", _nodeCount);
786+ _tree->setDirtyBit();
778787 setupNewVoxelsForDrawing();
779788 }
780789
@@ -795,6 +804,84 @@ void VoxelSystem::falseColorizeInView(ViewFrustum* viewFrustum) { · 14 unmodified lines
795804 _nodeCount = 0;
796805 _tree->recurseTreeWithOperation(falseColorizeInViewOperation,(void*)viewFrustum);
797806 qDebug("setting in view false color for %d nodes\n", _nodeCount);
807+ _tree->setDirtyBit();
808+ setupNewVoxelsForDrawing();
809+}
810+
811+// combines the removeOutOfView args into a single class
812+class groupColor {
813+public:
814+ unsigned char red, green, blue;
815+ groupColor(unsigned char red, unsigned char green, unsigned char blue) :
816+ red(red), green(green), blue(blue) { };
817+
818+ groupColor(const groupColor& color) :
819+ red(color.red), green(color.green), blue(color.blue) { };
820+
821+ groupColor() :
822+ red(0), green(0), blue(0) { };
823+
824+};
825+
826+class colorizeBySourceArgs {
827+public:
828+ std::map<uint16_t, groupColor> colors;
829+};
830+
831+// Will false colorize voxels that are not in view
832+bool VoxelSystem::falseColorizeBySourceOperation(VoxelNode* node, void* extraData) {
833+ colorizeBySourceArgs* args = (colorizeBySourceArgs*)extraData;
834+ _nodeCount++;
835+ if (node->isColored()) {
836+ // pick a color based on the source - we want each source to be obviously different
837+ uint16_t nodeID = node->getSourceID();
838+
839+ //printf("false colorizing from source %d, color: %d, %d, %d\n", nodeID,
840+ // args->colors[nodeID].red, args->colors[nodeID].green, args->colors[nodeID].blue);
841+
842+ node->setFalseColor(args->colors[nodeID].red, args->colors[nodeID].green, args->colors[nodeID].blue);
843+ }
844+ return true; // keep going!
845+}
846+
847+void VoxelSystem::falseColorizeBySource() {
848+ _nodeCount = 0;
849+ colorizeBySourceArgs args;
850+ const int NUMBER_OF_COLOR_GROUPS = 3;
851+ const unsigned char MIN_COLOR = 128;
852+ int voxelServerCount = 0;
853+ groupColor groupColors[NUMBER_OF_COLOR_GROUPS] = { groupColor(255, 0, 0),
854+ groupColor(0, 255, 0),
855+ groupColor(0, 0, 255)};
856+
857+ // create a bunch of colors we'll use during colorization
858+ NodeList* nodeList = NodeList::getInstance();
859+ for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {
860+ if (node->getType() == NODE_TYPE_VOXEL_SERVER) {
861+ uint16_t nodeID = node->getNodeID();
862+ int groupColor = voxelServerCount % NUMBER_OF_COLOR_GROUPS;
863+ args.colors[nodeID] = groupColors[groupColor];
864+
865+ //printf("assigning color for source %d, color: %d, %d, %d\n", nodeID,
866+ // args.colors[nodeID].red, args.colors[nodeID].green, args.colors[nodeID].blue);
867+
868+ if (groupColors[groupColor].red > 0) {
869+ groupColors[groupColor].red = ((groupColors[groupColor].red - MIN_COLOR)/2) + MIN_COLOR;
870+ }
871+ if (groupColors[groupColor].green > 0) {
872+ groupColors[groupColor].green = ((groupColors[groupColor].green - MIN_COLOR)/2) + MIN_COLOR;
873+ }
874+ if (groupColors[groupColor].blue > 0) {
875+ groupColors[groupColor].blue = ((groupColors[groupColor].blue - MIN_COLOR)/2) + MIN_COLOR;
876+ }
877+
878+ voxelServerCount++;
879+ }
880+ }
881+
882+ _tree->recurseTreeWithOperation(falseColorizeBySourceOperation, &args);
883+ qDebug("setting false color by source for %d nodes\n", _nodeCount);
884+ _tree->setDirtyBit();
798885 setupNewVoxelsForDrawing();
799886 }
800887
@@ -848,6 +935,7 @@ void VoxelSystem::falseColorizeDistanceFromView(ViewFrustum* viewFrustum) { · 47 unmodified lines
848935 _nodeCount = 0;
849936 _tree->recurseTreeWithOperation(falseColorizeDistanceFromViewOperation,(void*)viewFrustum);
850937 qDebug("setting in distance false color for %d nodes\n", _nodeCount);
938+ _tree->setDirtyBit();
851939 setupNewVoxelsForDrawing();
852940 }
853941
@@ -1027,6 +1115,7 @@ void VoxelSystem::falseColorizeRandomEveryOther() { · 173 unmodified lines
10271115 _tree->recurseTreeWithOperation(falseColorizeRandomEveryOtherOperation,&args);
10281116 qDebug("randomized false color for every other node: total %ld, colorable %ld, colored %ld\n",
10291117 args.totalNodes, args.colorableNodes, args.coloredNodes);
1118+ _tree->setDirtyBit();
10301119 setupNewVoxelsForDrawing();
10311120 }
10321121
@@ -1331,6 +1420,7 @@ void VoxelSystem::falseColorizeOccluded() { · 298 unmodified lines
13311420
13321421 //myCoverageMap.erase();
13331422
1423+ _tree->setDirtyBit();
13341424 setupNewVoxelsForDrawing();
13351425 }
13361426
@@ -1447,6 +1537,7 @@ void VoxelSystem::falseColorizeOccludedV2() { · 110 unmodified lines
14471537 //myCoverageMapV2.erase();
14481538
14491539
1540+ _tree->setDirtyBit();
14501541 setupNewVoxelsForDrawing();
14511542 }
14521543