예제 #1
0
Z3DPunctaFilter::Z3DPunctaFilter()
  : Z3DGeometryFilter()
  , m_sphereRenderer(NULL)
  , m_boundBoxRenderer(NULL)
  , m_showPuncta("Show Puncta", true)
  , m_colorMode("Color Mode")
  , m_singleColorForAllPuncta("Puncta Color", glm::vec4(ZRandomInstance.randReal<float>(),
                                                       ZRandomInstance.randReal<float>(),
                                                       ZRandomInstance.randReal<float>(),
                                                       1.f))
  , m_useSameSizeForAllPuncta("Use Same Size", false)
  , m_pressedPunctum(NULL)
  , m_selectedPuncta(NULL)
  , m_xCut("X Cut", glm::ivec2(0,0), 0, 0)
  , m_yCut("Y Cut", glm::ivec2(0,0), 0, 0)
  , m_zCut("Z Cut", glm::ivec2(0,0), 0, 0)
  , m_widgetsGroup(NULL)
  , m_dataIsInvalid(false)
{
  m_singleColorForAllPuncta.setStyle("COLOR");
  connect(&m_singleColorForAllPuncta, SIGNAL(valueChanged()), this, SLOT(prepareColor()));

  // Color Mode
  m_colorMode.addOptions("Same Color", "Random Color", "Based on Point Source", "Original Point Color");
  m_colorMode.select("Based on Point Source");

  connect(&m_colorMode, SIGNAL(valueChanged()), this, SLOT(prepareColor()));
  connect(&m_colorMode, SIGNAL(valueChanged()), this, SLOT(adjustWidgets()));

  connect(&m_useSameSizeForAllPuncta, SIGNAL(valueChanged()), this, SLOT(changePunctaSize()));


  addParameter(m_showPuncta);
  addParameter(m_colorMode);

  addParameter(m_singleColorForAllPuncta);

  addParameter(m_useSameSizeForAllPuncta);

  m_selectPunctumEvent = new ZEventListenerParameter("Select Puncta", true, false, this);
  m_selectPunctumEvent->listenTo("select punctum", Qt::LeftButton, Qt::NoModifier, QEvent::MouseButtonPress);
  m_selectPunctumEvent->listenTo("select punctum", Qt::LeftButton, Qt::NoModifier, QEvent::MouseButtonRelease);
  m_selectPunctumEvent->listenTo("append select punctum", Qt::LeftButton, Qt::ControlModifier, QEvent::MouseButtonPress);
  m_selectPunctumEvent->listenTo("append select punctum", Qt::LeftButton, Qt::ControlModifier, QEvent::MouseButtonRelease);
  connect(m_selectPunctumEvent, SIGNAL(mouseEventTriggered(QMouseEvent*,int,int)), this, SLOT(selectPuncta(QMouseEvent*,int,int)));
  addEventListener(m_selectPunctumEvent);

  addParameter(m_xCut);
  addParameter(m_yCut);
  addParameter(m_zCut);
  connect(&m_xCut, SIGNAL(valueChanged()), this, SLOT(setClipPlanes()));
  connect(&m_yCut, SIGNAL(valueChanged()), this, SLOT(setClipPlanes()));
  connect(&m_zCut, SIGNAL(valueChanged()), this, SLOT(setClipPlanes()));
  adjustWidgets();
}
/**
 * Create new image for the given shape.
 */
SDL_Surface *
ShapeBuilder::createImage(const Shape *shape, Cube::eWeight weight)
{
    static const SDL_Color TRANSPARENT = {255, 0, 255, 255};

    SDL_Surface *surface = SurfaceTool::createTransparent(
                               shape->getW() * View::SCALE, shape->getH() * View::SCALE,
                               TRANSPARENT);

    SDL_Rect rect;
    rect.w = View::SCALE;
    rect.h = View::SCALE;

    SDL_Color color;
    prepareColor(&color, shape, weight);

    Shape::const_iterator end = shape->marksEnd();
    for (Shape::const_iterator i = shape->marksBegin(); i != end; ++i) {
        rect.x = i->getX() * View::SCALE;
        rect.y = i->getY() * View::SCALE;
        SurfaceTool::alphaFill(surface, &rect, color);
    }

    return surface;
}
예제 #3
0
Ticker::Ticker()
{
    timer.setInterval(1000 * 10); // 10 seconds
    connect(&timer, SIGNAL(timeout()), this, SLOT(advanceTicker()));
    //game = pgame;
    show = false;
    prepareColor();
    setRect(0,0,WIDTH,74);
}
예제 #4
0
void UnixTerminal::prepare()
{
	ADDTOCALLSTACK("UnixTerminal::prepare");
	ASSERT(m_prepared == false);

#ifdef _USECURSES
	initscr();	// init screen
	cbreak();	// read one character at a time
	echo();		// echo input

	// create a window, same size as terminal
	int lines, columns;
	getmaxyx(stdscr, lines, columns);
	m_window = newwin(lines, columns, 0, 0);

	keypad(m_window, TRUE);		// process special chars
	nodelay(m_window, TRUE);	// non-blocking input
	scrollok(m_window, TRUE);	// allow scrolling
	refresh();		// draw screen

#else
	// save existing attributes
	if (tcgetattr(STDIN_FILENO, &m_original) < 0)
		throw CGrayError(LOGL_WARN, 0, "failed to get terminal attributes");

	// set new terminal attributes
	termios term_caps = m_original;
	term_caps.c_lflag &= ~(ICANON | ECHO);
	term_caps.c_cc[VMIN] = 1;

	if (tcsetattr(STDIN_FILENO, TCSANOW, &term_caps) < 0)
		throw CGrayError(LOGL_WARN, 0, "failed to set terminal attributes");

	setbuf(stdin, NULL);
#endif

	prepareColor();
	m_nextChar = '\0';
	m_prepared = true;
}
예제 #5
0
void screen_credits ()
{
    if ( DEV > 1 ) return;

    music_stop();
    displayOff(0);
    resetScreen();

    VDP_setTextPalette ( PAL0 );
    prepareColor (  1, 0xfff );
    prepareColor (  2, 0x444 );
    prepareColor ( 17, font_palette.data [ 7 ] );
    prepareColor ( 18, font_palette.data [ 8 ] );
    prepareColor ( 33, 0xfff );
    prepareColor ( 34, 0x444 );

    writeCredits ( 1, 4 );
    writeCredits ( 2, 4 );
    writeCredits ( 3, 9 );

    //waitSc(2);
}
예제 #6
0
파일: MeshView.cpp 프로젝트: HennyN/QBeam3d
void MeshView::drawMesh( DRAW_MODE d )
{
    if( m_meshPtr )
    {
        std::cout << "MeshView::drawMesh()" << std::endl;

        m_meshPtr->lock();

        Mesh::ConstFaceIter fIt(m_meshPtr->faces_begin()),
             fEnd(m_meshPtr->faces_end());
        Mesh::ConstFaceVertexIter fvIt;
        Mesh::ConstVertexIter vIt(m_meshPtr->vertices_begin());

        float color[4] = { 1.0, 1.0, 1.0, 1.0 };

        switch( d )
        {
        case POINTS_ONLY:
            glBegin(GL_POINTS);
            glColor3fv(color);
            for(; vIt!=m_meshPtr->vertices_end(); ++vIt)
            {
                if( prepareColor( color, m_meshPtr->color(vIt) ) )
                    glColor3fv(color);
                glVertex3dv(m_meshPtr->point(vIt));
            }
            glEnd();
            break;
        case WIREFRAME:
            for (; fIt!=fEnd; ++fIt)
            {
                glBegin(GL_LINE_STRIP);
                glColor3fv(color);
                fvIt = m_meshPtr->cfv_iter(fIt.handle());
                if( prepareColor( color, m_meshPtr->color(fvIt) ) )
                    glColor3fv(color);
                glVertex3dv(m_meshPtr->point(fvIt));
                ++fvIt;
                if( prepareColor( color, m_meshPtr->color(fvIt) ) )
                    glColor3fv(color);
                glVertex3dv(m_meshPtr->point(fvIt));
                ++fvIt;
                if( prepareColor( color, m_meshPtr->color(fvIt) ) )
                    glColor3fv(color);
                glVertex3dv(m_meshPtr->point(fvIt));
                glEnd();
            }
            break;
        case FACETS:
        case FLAT_FACET:
            glBegin(GL_TRIANGLES);
            glColor3fv(color);
            for (; fIt!=fEnd; ++fIt)
            {
                glNormal3fv( m_meshPtr->normal( fIt.handle() ) );
                fvIt = m_meshPtr->cfv_iter(fIt.handle());
                if( prepareColor( color, m_meshPtr->color(fvIt) ) )
                    glColor3fv(color);
                glVertex3dv(m_meshPtr->point(fvIt));
                ++fvIt;
                if( prepareColor( color, m_meshPtr->color(fvIt) ) )
                    glColor3fv(color);
                glVertex3dv(m_meshPtr->point(fvIt));
                ++fvIt;
                if( prepareColor( color, m_meshPtr->color(fvIt) ) )
                    glColor3fv(color);
                glVertex3dv(m_meshPtr->point(fvIt));
            }
            glEnd();
            break;
        case SMOOTH_FACET:
            glBegin(GL_TRIANGLES);
            glColor3fv(color);
            for (; fIt!=fEnd; ++fIt)
            {
                fvIt = m_meshPtr->cfv_iter(fIt.handle());
                glNormal3fv(m_meshPtr->normal(fvIt.handle()) );
                if( prepareColor( color, m_meshPtr->color(fvIt) ) )
                    glColor3fv(color);
                glVertex3dv(m_meshPtr->point(fvIt));
                ++fvIt;
                glNormal3fv(m_meshPtr->normal(fvIt.handle()));
                if( prepareColor( color, m_meshPtr->color(fvIt) ) )
                    glColor3fv(color);
                glVertex3dv(m_meshPtr->point(fvIt));
                ++fvIt;
                glNormal3fv(m_meshPtr->normal(fvIt.handle()));
                if( prepareColor( color, m_meshPtr->color(fvIt) ) )
                    glColor3fv(color);
                glVertex3dv(m_meshPtr->point(fvIt));
            }
            glEnd();
            break;
        default:
            break;
        }
        //glFlush();
        m_meshPtr->unlock();
        setDirty(false);
        //std::cout << " } MeshView::drawMesh()" << std::endl;
    }
}
예제 #7
0
void Z3DPunctaFilter::prepareData()
{
  if (!m_dataIsInvalid)
    return;

  deregisterPickingObjects(getPickingManager());

  // convert puncta to format that glsl can use
  m_specularAndShininess.clear();
  m_pointAndRadius.clear();
  //m_sourceColorMapper.clear();
  int xMin = std::numeric_limits<int>::max();
  int xMax = std::numeric_limits<int>::min();
  int yMin = std::numeric_limits<int>::max();
  int yMax = std::numeric_limits<int>::min();
  int zMin = std::numeric_limits<int>::max();
  int zMax = std::numeric_limits<int>::min();
  for (size_t i=0; i<m_punctaList.size(); i++) {
    if (m_useSameSizeForAllPuncta.get())
      m_pointAndRadius.push_back(glm::vec4(m_punctaList[i]->x(), m_punctaList[i]->y(), m_punctaList[i]->z(), 2.f));
    else
      m_pointAndRadius.push_back(glm::vec4(m_punctaList[i]->x(), m_punctaList[i]->y(), m_punctaList[i]->z(), m_punctaList[i]->radius()));
    if (m_punctaList[i]->x() > xMax)
      xMax = static_cast<int>(std::ceil(m_punctaList[i]->x()));
    if (m_punctaList[i]->x() < xMin)
      xMin = static_cast<int>(std::floor(m_punctaList[i]->x()));
    if (m_punctaList[i]->y() > yMax)
      yMax = static_cast<int>(std::ceil(m_punctaList[i]->y()));
    if (m_punctaList[i]->y() < yMin)
      yMin = static_cast<int>(std::floor(m_punctaList[i]->y()));
    if (m_punctaList[i]->z() > zMax)
      zMax = static_cast<int>(std::ceil(m_punctaList[i]->z()));
    if (m_punctaList[i]->z() < zMin)
      zMin = static_cast<int>(std::floor(m_punctaList[i]->z()));
    m_specularAndShininess.push_back(glm::vec4(m_punctaList[i]->maxIntensity()/255.f,
                                               m_punctaList[i]->maxIntensity()/255.f,
                                               m_punctaList[i]->maxIntensity()/255.f,
                                               m_punctaList[i]->maxIntensity()/2.f));
  }
  //for (size_t i=0; i<m_origPunctaList.size(); ++i)
    //m_sourceColorMapper.insert(std::pair<QString, size_t>(m_origPunctaList[i]->source(), 0));

  m_xCut.setRange(xMin, xMax);
  m_xCut.set(glm::ivec2(xMin, xMax));
  m_yCut.setRange(yMin, yMax);
  m_yCut.set(glm::ivec2(yMin, yMax));
  m_zCut.setRange(zMin, zMax);
  m_zCut.set(glm::ivec2(zMin, zMax));

  //  std::map<QString,size_t>::iterator it;
  //  size_t index = 0;
  //  size_t numOfPrevColor = m_colorsForDifferentSource.size();
  //  for (it = m_sourceColorMapper.begin(); it != m_sourceColorMapper.end(); it++) {
  //    m_sourceColorMapper[it->first] = index++;
  //    if (index > numOfPrevColor) {
  //      QString guiname = QString("Source %1 Color").arg(index);
  //      m_colorsForDifferentSource.push_back(new ZVec4Parameter(guiname, glm::vec4(
  //                                                                ZRandomInstance.randReal<float>(),
  //                                                                ZRandomInstance.randReal<float>(),
  //                                                                ZRandomInstance.randReal<float>(),
  //                                                                1.f)));
  //      m_colorsForDifferentSource[index-1]->setStyle("COLOR");
  //      connect(m_colorsForDifferentSource[index-1], SIGNAL(valueChanged()), this, SLOT(prepareColor()));
  //    }
  //  }
  //  if (m_widgetsGroup) {
  //    for (size_t i=0; i<m_colorsForDifferentSourceWidgetsGroup.size(); i++) {
  //      delete m_colorsForDifferentSourceWidgetsGroup[i];
  //    }
  //    m_colorsForDifferentSourceWidgetsGroup.clear();
  //  }
  //  if (numOfPrevColor < index) {
  //    for (size_t i=numOfPrevColor; i<m_colorsForDifferentSource.size(); i++) {
  //      addParameter(m_colorsForDifferentSource[i]);
  //    }
  //  } else if (numOfPrevColor > index) {
  //    for (size_t i=index; i<m_colorsForDifferentSource.size(); i++) {
  //      removeParameter(m_colorsForDifferentSource[i]);
  //      delete m_colorsForDifferentSource[i];
  //    }
  //    m_colorsForDifferentSource.resize(index);
  //  }

  bool needUpdateWidget = false;
  QList<QString> allSources;
  for (size_t i=0; i<m_origPunctaList.size(); ++i) {
    int idx = allSources.indexOf(m_origPunctaList[i]->source());
    if (idx == -1) {
      allSources.push_back(m_origPunctaList[i]->source());
      idx = allSources.size() - 1;
    }
    QString guiname = QString("Source %1 Color").arg(idx + 1);
    if (m_sourceColorMapper.find(m_origPunctaList[i]->source()) == m_sourceColorMapper.end()) {
      m_sourceColorMapper[m_origPunctaList[i]->source()] =
          new ZVec4Parameter(guiname, glm::vec4(ZRandomInstance.randReal<float>(),
                                                ZRandomInstance.randReal<float>(),
                                                ZRandomInstance.randReal<float>(),
                                                1.f));
      m_sourceColorMapper[m_origPunctaList[i]->source()]->setStyle("COLOR");
      connect(m_sourceColorMapper[m_origPunctaList[i]->source()], SIGNAL(valueChanged()),
          this, SLOT(prepareColor()));
      addParameter(m_sourceColorMapper[m_origPunctaList[i]->source()]);
      needUpdateWidget = true;
    } else {
      m_sourceColorMapper[m_origPunctaList[i]->source()]->setName(guiname);
    }
  }
  // remove colors for not exist puncta source
  std::map<QString, ZVec4Parameter*>::iterator it = m_sourceColorMapper.begin();
  while (it != m_sourceColorMapper.end()) {
    if (!allSources.contains(it->first)) {
      std::map<QString, ZVec4Parameter*>::iterator itCopy = it;
      ++it;
      removeParameter(itCopy->second);
      delete itCopy->second;
      m_sourceColorMapper.erase(itCopy);
      needUpdateWidget = true;
    } else
      ++it;
  }
  if (needUpdateWidget)
    updateWidgetsGroup();

  m_sphereRenderer->setData(&m_pointAndRadius, &m_specularAndShininess);
  prepareColor();
  adjustWidgets();
  //if (numOfPrevColor != index)   // number of puncta source changed
    //updateWidgetsGroup();
  m_dataIsInvalid = false;
}