0

我是一个项目的一部分,我正在处理管道系统 3D 渲染的选择方法。为了能够选择管道,我的研究表明颜色选择将是最好的方法(由于管道的数量,光线选择可能更困难)。

//define color for pipe
int lowc=0;
int highc=9;
float cB = (rand()%(highc-lowc+1)+lowc)/10.0;
float cG = (rand()%(highc-lowc+1)+lowc)/10.0;
float cR = (rand()%(highc-lowc+1)+lowc)/10.0;
//some way of confirming the complete color combination is unique.

 // Create and insert new pipe in a new branch..
 Pipe* new_p = new Pipe(new_n1, new_n2, d, wf,cB,cG,cR);
 ElementList* new_branch = new ElementList();
 new_branch->branch->Append(new_n1);
 new_branch->branch->Append(new_p);
 new_branch->branch->Append(new_n2); 

目前我正在努力找出最有效的方法来检查定义的颜色是否已经存在。存储所有 1000 个当前颜色组合的向量似乎太耗时,因为为每个引用所有其他现有节点颜色值也是如此。是否有更好的解决方案来存储现有颜色的向量(例如 <0.2、0.6、0.4>、<0.8、0.1、0.1> 等)并将其与任何其他现有向量进行比较?

4

2 回答 2

0

我可以举一个例子来挑选物体的三角形。您应该将此示例更改为渲染管索引而不是面索引。

PickingModeBegin(); // see below

glBegin(GL_TRIANGLES);
for (FaceIndex fi = 0; fi < GetFacesSize(); fi++) {
    const Face & face = faces[fi];
    glColor3ub((fi >> 16) & 255, (fi >> 8) & 255, (fi & 255)); // color coded index
    glVertex3fv(vertices[face.a].GetPointer());
    glVertex3fv(vertices[face.b].GetPointer());
    glVertex3fv(vertices[face.c].GetPointer());
}
glEnd();

PickingModeEnd(); // see below

glReadBuffer(GL_BACK);                          
GLint viewportInfo[4];
glGetIntegerv(GL_VIEWPORT, viewportInfo);             

GLubyte pixel[3];
// read the color
glReadPixels(mousePosX, viewportInfo[3] - mousePosY, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, pixel);             

// extract face index
int selectedFaceIdx = (pixel[0] << 16) + (pixel[1] << 8) + pixel[2]; 



void PickingModeBegin(void) {
  glPushAttrib(GL_ENABLE_BIT | GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
  glCullFace(GL_BACK);
  glEnable(GL_CULL_FACE);


  // turn off everything
  glDisable(GL_BLEND);
  glDisable(GL_DITHER);
  glDisable(GL_FOG);
  glDisable(GL_LIGHTING);
  glDisable(GL_TEXTURE_1D);
  glDisable(GL_TEXTURE_2D);
  glDisable(GL_TEXTURE_3D);
  glShadeModel(GL_FLAT);
  glEnable(GL_DEPTH_TEST);
  glDepthFunc(GL_LESS);

  glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

}

void PickingModeEnd(void) {
  glPopAttrib();
}
于 2013-10-10T14:00:24.117 回答
0
struct ColourValue
{
    int red, blue, green;

    ColourValue() : red(0), blue(0), green(0) {}
    ColourValue(int red, int blue, int green) : red(red), blue(blue), green(green) {}

    bool operator < (const ColourValue& other) const
    {
        // magic trick to sort in set
        return pair<int, pair<int, int>>(this->red, pair<int, int>(this->blue, this->green))
        < pair<int, pair<int, int>>(other.red, pair<int, int>(other.blue, other.green));
    }
};

set<ColourValue> all_colours;
于 2013-10-10T14:09:39.343 回答