// dependent on a change in parameters, write new colors to the TriMesh void GeoDeVisualizerApp::writeColors() { mTriangles.getColorsRGB().clear(); vector<Color> colors; colors.reserve(mTriangles.getNumTriangles()); DisplayMode mode = (DisplayMode)mCurParams.displayMode; switch(mode) { case Geography: { colors = mWorld.mGeoColors; break; } case Colonies: { colors = mWorld.mGeoColors; // add sphere of influence and location Colony& colRef = mWorld.mColonies[mCurParams.displayColony]; mCamVars.sceneRotation.set(getAverageVertex(colRef.mLocation), mCam.getEyePoint()); for (set<u32>::iterator soiIt = colRef.mSphereInfluence.begin(); soiIt != colRef.mSphereInfluence.end(); ++soiIt) { colors[*soiIt] = Color(0.2, 0.2, 0.2); } colors[colRef.mLocation] = Color(1.0, 0.0, 0.0); break; } case Resources: { vector<u32> activeResIdxs; for (u32 i = 0; i < mCurParams.numResources; i++) { if (mCurParams.showResources[i]) { activeResIdxs.push_back(i); } } if (activeResIdxs.size() > 0) { colors.insert(colors.begin(), mTriangles.getNumTriangles(), Color(0.0, 0.0, 0.0)); } else { colors.insert(colors.begin(), mTriangles.getNumTriangles(), Color(0.2, 0.2, 0.2)); break; } float numIndices = activeResIdxs.size(); for(vector<u32>::iterator idxIt = activeResIdxs.begin(); idxIt != activeResIdxs.end(); ++idxIt) { vector<f32>& activeResVals = (mWorld.resources())[*idxIt].mVals; vector<Color>::iterator colIt = colors.begin(); for (vector<f32>::iterator valIt = activeResVals.begin(); valIt != activeResVals.end(); ++valIt) { *colIt += (resourceColors[*idxIt] * (*valIt)) / numIndices; colIt++; } } break; } case Attributes: { colors.insert(colors.begin(), mTriangles.getNumTriangles(), Color(0.0, 0.0, 0.0)); vector<u32> activeAttrIdxs; for (u32 i = 0; i < NUM_ATTRIBUTES; i++) { if (mCurParams.showAttributes[i]) { activeAttrIdxs.push_back(i); } } if (activeAttrIdxs.size() == 0) { colors.clear(); colors.insert(colors.begin(), mTriangles.getNumTriangles(), Color(0.1, 0.1, 0.1)); break; } map<string, Color> attrMap; attrMap["wetness"] = Color(0.0, 0.0, 1.0); attrMap["temperature"] = Color(1.0, 0.0, 0.0); attrMap["elevation"] = Color(0.0, 1.0, 0); // iterate through all active indices for(vector<u32>::iterator idxIt = activeAttrIdxs.begin(); idxIt != activeAttrIdxs.end(); ++idxIt) { Color colorVal = attrMap[mWorld.mAttributes[*idxIt].mName]; vector<Color>::iterator faceColorIt = colors.begin(); // iterate through all attribute values for (vector<f32>::iterator attrIt = mWorld.mAttributes[*idxIt].mVals.begin(); attrIt != mWorld.mAttributes[*idxIt].mVals.end(); ++attrIt) { *faceColorIt += (colorVal * (*attrIt)); faceColorIt++; } } break; } } // triple the colors vector so that triangles show up as solid triangles for (vector<Color>::iterator colIt = colors.begin(); colIt != colors.end(); ++colIt) { mTriangles.appendColorRgb(*colIt); mTriangles.appendColorRgb(*colIt); mTriangles.appendColorRgb(*colIt); } mFrame = mTriangles; mFrame.getColorsRGB().clear(); vector<Color> frameColors(colors.size()*3, Color(0.1, 0.1, 0.1)); mFrame.appendColorsRgb(frameColors.data(), frameColors.size()); }