void Colorize(vtkSmartPointer<vtkPolyData> mesh, std::vector<Camera> dataset) { assert(not dataset.empty()); auto colors = vtkSmartPointer<vtkUnsignedCharArray>::New(); colors->SetNumberOfComponents(3); colors->SetName("Colors"); auto *const meshNormals = mesh->GetPointData()->GetNormals(); for (auto idx = 0; idx < mesh->GetNumberOfPoints(); ++idx) { // camera image indexes and appropriate dot product std::map<std::size_t, double> angles; auto normal = GetNormal(meshNormals, idx); angles[0] = normal.dot(dataset[0].getDirection()); for (std::size_t j = 1; j < dataset.size(); ++j) { auto angle = normal.dot(dataset[j].getDirection()); if (angle >= 0.5) { angles[j] = angle; } } Color<double> color = getAverageColor(mesh, dataset, idx, angles); colors->InsertNextTuple(reinterpret_cast<double *>(&color)); } mesh->GetPointData()->SetScalars(colors); }
void TColorStyle::drawStroke(TFlash &flash, const TStroke *s) const { bool isCenterline = false; double minThickness, maxThickness = 0; std::wstring quality = flash.getLineQuality(); double thickness = computeAverageThickness(s, minThickness, maxThickness); if (minThickness == maxThickness && minThickness == 0) return; if (quality == TFlash::ConstantLines) isCenterline = true; else if (quality == TFlash::MixedLines && (maxThickness == 0 || minThickness / maxThickness > 0.5)) isCenterline = true; else if (quality == TFlash::VariableLines && maxThickness - minThickness < 0.16) // Quando si salva il pli, si approssima al thick. // L'errore di approx e' sempre 0.1568... isCenterline = true; // else assert(false); flash.setFillColor(getAverageColor()); // flash.setFillColor(TPixel::Red); TStroke *saux = const_cast<TStroke *>(s); if (isCenterline) { saux->setAverageThickness(thickness); flash.setThickness(s->getAverageThickness()); flash.setLineColor(getAverageColor()); flash.drawCenterline(s, false); } else { saux->setAverageThickness(0); if (!flash.drawOutline(saux)) { flash.setThickness(thickness); flash.setLineColor(getAverageColor()); flash.drawCenterline(s, false); } } }
void ZBlock::setColor(int time, ZMode zmode) { currentZMode = zmode; if(zmode == ZMode::Average) { activeColor = getAverageColor(time); }else if(zmode == ZMode::Cumulative) { activeColor = getCumulativeColor(time); }else if(zmode == ZMode::Frequency) { activeColor = getFrequencyColor(time); }else if(zmode == ZMode::Highest) { activeColor = getHighestColor(time); }else activeColor = Qt::white; }
TPixel32 StylePicker::pickColor(TStroke *stroke) const { return getAverageColor(stroke); }
TPixel32 StylePicker::pickColor(const TRectD &area) const { //TRectD rect=area.enlarge(-1,-1); return getAverageColor(convert(area)); }
//-------------------------------------------------------------- void testApp::update(){ if (!recording && !needsRedraw) return; //recording a sequence, add some points, rebuild if (recording) { int cursize = voronoi.getPoints().size(); if (cursize >= endpoints) { cout << "done! drew " << voronoi.cells.size() << " cells" << endl; recording = false; needsRedraw = false; savelast = true; } else { int newpoints = max((double)1.0, round(cursize * scalerate)); if (cursize + newpoints > endpoints) newpoints = endpoints - cursize; cout << "adding " << newpoints << " points" << endl; addVoronoiPoints(newpoints); buildVoronoi(); } } else { //single image, add/remove points and rebuild if necessary int pointdiff = npoints - voronoi.getPoints().size(); if (pointdiff > 0) { cout << "adding " << pointdiff << " points" << endl; addVoronoiPoints(pointdiff); buildVoronoi(); } else if (pointdiff < 0) { cout << "removing " << abs(pointdiff) << " points" << endl; vector<ofPoint>& vpts = voronoi.getPoints(); vpts.erase(vpts.begin()+npoints, vpts.begin() + vpts.size()); buildVoronoi(); } } //draw the picture fbo.begin(); for (int i = 0; i < voronoi.cells.size(); i++) { ofxVoronoiCell cell = voronoi.cells.at(i); ofRectangle bound(ofGetWidth()+1, ofGetHeight()+1, -1, -1); ofPath path; int nverts = cell.pts.size(); float *vertx = new float[cell.pts.size()]; float *verty = new float[cell.pts.size()]; for (int j = 0; j < cell.pts.size(); j++) { ofPoint p = cell.pts[j]; if (p.x < 0) p.x = 0; vertx[j] = p.x; verty[j] = p.y; if (p.x < bound.x) bound.x = p.x; if (p.x > bound.width) bound.width = p.x; if (p.y < bound.y) bound.y = p.y; if (p.y > bound.height) bound.height = p.y; path.lineTo(cell.pts[j]); } path.setFilled(true); ofColor c = getAverageColor(img, bound, nverts, vertx, verty); path.setFillColor(c); path.setStrokeColor(ofColor(0, 0, 0)); path.draw(); if (c.r == 0 && c.b == 0 && c.g == 0) { cout << "dead spot" << endl; cout << bound.x << " -> " << bound.width << ", "; cout << bound.y << " -> " << bound.height << endl; for (int j = 0; j < cell.pts.size(); j++) { ofPoint p = cell.pts[j]; cout << p << endl; } } delete [] vertx; delete [] verty; } fbo.end(); if (!recording) needsRedraw = false; }