Example #1
0
void LCube::setNodeColor(scene::ISceneNode* node, int c){
	video::SColor color;
	switch(c){
	case C_LED_OFF:
		color = video::SColor(255, 255, 255, 255);
		break;
	case C_LED_RED:
		color = video::SColor(255, 255, 0, 0);
		break;
	case C_LED_GREEN:
		color = video::SColor(255, 0, 255, 0);
		break;
	case C_LED_BLUE:
		color = video::SColor(255, 0, 0, 255);
		break;
	case C_LED_YELLOW:
		color = video::SColor(255, 255, 255, 0);
		break;
	case C_LED_CYAN:
		color = video::SColor(255, 0, 255, 255);
		break;
	case C_LED_MAGENTA:
		color = video::SColor(255, 255, 0, 255);
		break;
	case C_LED_ON:
		color = _onColor;
	}

	setNodeColor(node, color);
}
Example #2
0
void LCube::reset(){
	for(size_t i = 0; i < _allNodes.size(); i++){
		_ledStates[i] = C_LED_OFF;
		_allNodes[i]->setParent(_offNode);
		setNodeColor(_allNodes[i], video::SColor(255, 255, 255, 255));
	}
}
Example #3
0
void LCube::load(std::vector<int> ledStates){
	_ledStates = ledStates;

	for(size_t i = 0; i < _allNodes.size(); i++){
		_allNodes[i]->setParent((_ledStates[i] != C_LED_OFF) ? _onNode : _offNode);
		setNodeColor(_allNodes[i], _ledStates[i]);
	}
}
Example #4
0
void Properties::changeNodeColor() {
    QColor color = QColorDialog::getColor(nodeColor);
    if (color.isValid()) {
        setNodeColor(color);
        QUndoCommand* changeColorCommand = new ChangeColorCommand(octree, color);
        undoStack->push(changeColorCommand);
    }
}
Example #5
0
Properties::Properties(OctreeEditor* octree, Viewport* viewport, QUndoStack* undoStack, QWidget* parent) :
    QWidget(parent),
    ui(new Ui::Properties),
    octree(octree),
    viewport(viewport),
    undoStack(undoStack) {
    ui->setupUi(this);
    ui->pushButtonColor->setAutoFillBackground(true);
    setNodeColor(QColor(Qt::blue));

    connect(ui->pushButtonColor, &QPushButton::clicked, this, &Properties::changeNodeColor);
    connect(ui->checkBoxShadeless, &QCheckBox::stateChanged, viewport, &Viewport::setShadeless);
    connect(octree, &OctreeEditor::nodeSelected, this, &Properties::onNodeSelected);
    connect(octree, &OctreeEditor::nodeDeselected, this, &Properties::onNodeDeselected);
    connect(ui->pushButtonPlus, &QPushButton::clicked, this, &Properties::levelPlus);
    connect(ui->pushButtonMinus, &QPushButton::clicked, this, &Properties::levelMinus);
    connect(ui->pushButtonReset, &QPushButton::clicked, this, &Properties::levelReset);

    onNodeDeselected();
}
int setNodeColor(Node **nodeArray, Color colors[], Node *colorNode, Color color)
{
    int result = 1;
    int index = colorNode->getIndex();
    switch (colors[index])
    {
    case RED:
        if (color == RED)
        {
            return 0;
        }
        DEBUG("Trying to set an already colored node, something is wrong");
        throw colorex;
    case GREEN:
        if (color == GREEN)
        {
            return 0;
        }
        DEBUG("Trying to set an already colored node, something is wrong");
        throw colorex;
    case BLUE:
        if (color == BLUE)
        {
            return 0;
        }
        DEBUG("Trying to set an already colored node, something is wrong");
        throw colorex;
    default:
        colors[index] = color;
        break;
    }
    set<int>::iterator iter = nodeArray[index]->getVertices();
    while (iter != nodeArray[index]->getVerticesEnd())
    {
        int secondaryIndex = *iter;
        iter++;
        switch (color)
        {
        case RED:
            if (colors[secondaryIndex] == RED)
            {
                DEBUG("Red conflict from %d and %d.", index, secondaryIndex);
                throw colorex;
            }
            if (colors[secondaryIndex] == GREEN || colors[secondaryIndex] == BLUE)
            {
                break;
            }
            colors[secondaryIndex] = (Color)(NOT_RED | colors[secondaryIndex]);
            break;
        case GREEN:
            if (colors[secondaryIndex] == GREEN)
            {
                DEBUG("Green conflict from %d and %d.", index, secondaryIndex);
                throw colorex;
            }
            if (colors[secondaryIndex] == RED || colors[secondaryIndex] == BLUE)
            {
                break;
            }
            colors[secondaryIndex] = (Color)(NOT_GREEN | colors[secondaryIndex]);
            break;
        case BLUE:
            if (colors[secondaryIndex] == BLUE)
            {
                DEBUG("Blue conflict from %d and %d.", index, secondaryIndex);
                throw colorex;
            }
            if (colors[secondaryIndex] == RED || colors[secondaryIndex] == GREEN)
            {
                break;
            }
            colors[secondaryIndex] = (Color)(NOT_BLUE | colors[secondaryIndex]);
            break;
    		default:
           	break;
        }
        switch (colors[secondaryIndex])
        {
        case NOT_RED_OR_GREEN:
            result += setNodeColor(nodeArray, colors, nodeArray[secondaryIndex], BLUE);
            break;
        case NOT_RED_OR_BLUE:
            result += setNodeColor(nodeArray, colors, nodeArray[secondaryIndex], GREEN);
            break;
        case NOT_GREEN_OR_BLUE:
            result += setNodeColor(nodeArray, colors, nodeArray[secondaryIndex], RED);
            break;
        case IMPOSSIBLE:
            DEBUG("Determined an impossible coloring.");
            throw colorex;
        default:
            break;
        }
    }
    return result;
}
void * taskGreedySearch(void *arg_in)
{
    Node **nodeArray = (Node **)arg_in;
    int last_state, last_type;
    pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &last_state);
    pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &last_type);
    DEBUG("Task three");

    DEBUG("Trying a simple greedy algorithm, no 3-clique optimization.");
    // Find the node with the highest vertex count and mark it RED
    int candidate = 0;
    for (unsigned int cntr = 1; cntr < g_count; cntr++)
    {
        if (nodeArray[candidate]->getVertexCount() < nodeArray[cntr]->getVertexCount())
        {
            candidate = cntr;
        }
    }
    // Find the node next to it with the highest vertex cound and mark it GREEN
    set<int>::iterator iter = nodeArray[candidate]->getVertices();
    int second = -1;
    while (iter != nodeArray[candidate]->getVerticesEnd())
    {
        int test = *iter;
        iter++;
        if (second == -1 || nodeArray[second]->getVertexCount() < nodeArray[test]->getVertexCount())
        {
            second = test;
				}
    }
    // Start marking all the nodes with the appropriate colors.
    Color colors[g_count];
    for (unsigned int cntr = 0; cntr < g_count; cntr++)
    {
        colors[cntr] = UNKNOWN;
    }
    int colored = 0;
    try
    {
       colored += setNodeColor(nodeArray, colors, nodeArray[candidate], RED);
       colored += setNodeColor(nodeArray, colors, nodeArray[second], GREEN);
    }
    catch (colorexception e)
    {
        DEBUG("Got an exception coloring the graph, must be unsolveable.");
        setSolution(NOT_COLORABLE, NULL);

        return ((void *) &SUCCESS);
    }
    
    // Could not do a straight compute of the answer - Time to get greedy
    Color colorTest[g_count];
    for (unsigned int cntr = 0; cntr < g_count; cntr++)
    {
        colorTest[cntr] = colors[cntr];
    }
    Solution greedySolution = greedySearch(nodeArray, colorTest);
    if (greedySolution == SOLVEABLE)
    {
        DEBUG("Greedy search found the problem to be solveable.");
        setSolution(SOLVEABLE, colorTest);
    }
    else
    {
        DEBUG("Greedy search returned %d.", greedySolution);
        setSolution(NOT_COLORABLE, NULL);
    }

    return ((void *) &SUCCESS);
}
void * taskGreedyThreeClique(void *arg_in)
{
    Node **nodeArray = (Node **)arg_in;
    int last_state, last_type;
    pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &last_state);
    pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &last_type);
    vector<ThreeClique> threeCliqueVector;
    DEBUG("Task two");

    // Determine if we have any 3 cliques
    // If we do start with the three clique with the highest vertex count.
    // Otherwise pick the single node with the highest vertex count.
    for (unsigned int aindex = 0; aindex + 3 < g_count; aindex++)
    {
        pthread_testcancel();
        if (nodeArray[aindex]->getVertexCount() < 3)
        {
            // This node does not have enough vertices to be a 4-clique
            continue;
        }
        set<int>::iterator b = nodeArray[aindex]->getVerticesAtOrAfter(aindex + 1);
        while (b != nodeArray[aindex]->getVerticesEnd())
        {
            int bindex = *b;
            b++;
            // Would be nice to skip the last 2 elements but the iterator has no "remaining" access.
            set<int>::iterator c = nodeArray[bindex]->getVerticesAtOrAfter(bindex + 1);
            while (c != nodeArray[bindex]->getVerticesEnd())
            {
                int cindex = *c;
                c++;
                if (! nodeArray[aindex]->hasVertex(cindex))
                {
                    continue;
                }
                // We have found a 3-clique add it to the list.
                threeCliqueVector.push_back(ThreeClique(nodeArray[aindex], nodeArray[bindex], nodeArray[cindex]));
                DEBUG(threeCliqueVector[threeCliqueVector.size() - 1].print().c_str());
            }
        }
    }

    if (threeCliqueVector.size() > 0)
    {
        DEBUG("We have %ld three-cliques, going greedy that way.", threeCliqueVector.size());
        // Determine the 3-count with the highest vertex count and start there.
        ThreeClique greediestClique = threeCliqueVector[0];
        unsigned int cntr;
        for (cntr = 1; cntr < threeCliqueVector.size(); cntr++)
        {
            pthread_testcancel();
            ThreeClique testClique = threeCliqueVector[cntr];
            if (greediestClique.getVertexCount() < testClique.getVertexCount())
            {
                DEBUG(testClique.print().c_str());
                greediestClique = testClique;
            }
        }
        DEBUG(greediestClique.print().c_str());

        // Start marking all the nodes with the appropriate colors.
        Color colors[g_count];
        for (cntr = 0; cntr < g_count; cntr++)
        {
            colors[cntr] = UNKNOWN;
        }
        unsigned int colored = 0;
        try
        {
           colored += setNodeColor(nodeArray, colors, greediestClique.getNodeA(), RED);
           colored += setNodeColor(nodeArray, colors, greediestClique.getNodeB(), GREEN);
           colored += setNodeColor(nodeArray, colors, greediestClique.getNodeC(), BLUE);
        }
        catch (colorexception e)
        {
            DEBUG("Got an exception coloring the graph, must be unsolveable.");
            setSolution(NOT_COLORABLE, NULL);

            return ((void *) &SUCCESS);
        }
        if (colored >= g_count)
        {
            DEBUG("We have colored %d nodes.", colored);

            // We were able to do a straight compute of the colors - return the result.
            setSolution(SOLVEABLE, colors);

            return ((void *) &SUCCESS);
        }

        // Could not do a straight compute of the answer - Time to get greedy
        Color colorTest[g_count];
        for (cntr = 0; cntr < g_count; cntr++)
        {
            colorTest[cntr] = colors[cntr];
        }
        Solution greedySolution = greedySearch(nodeArray, colorTest);
        if (greedySolution == SOLVEABLE)
        {
            DEBUG("Greedy search found the problem to be solveable.");
            setSolution(SOLVEABLE, colorTest);
        }
        else
        {
            DEBUG("Greedy search returned %d.", greedySolution);
            setSolution(NOT_COLORABLE, NULL);
        }
    }

    // If we found no 3-cliques that proves nothing.
    return ((void *) &SUCCESS);
}
gePropertyTransform::gePropertyTransform(rendererGL10* renderer, geGUIBase* parent, const char* name, Sprite2Dx* sprite, geFontManager* fontManager):
	geTreeNode(renderer, parent, name, sprite, fontManager, 10)
{
	m_pObject3dPtr=NULL;
	setSize(m_cSize.x, 85.0f);

	//geButton* btn=new geButton();
	//btn->create(this, "button1", 40, 10);

	//gePushButton* pbtn = new gePushButton("");
	//pbtn->create(this, "", 10, 10);

	m_pszTextBoxTranslation[0] = new geTextBox("X", fontManager);
	m_pszTextBoxTranslation[0]->create(renderer, this, "0.0", 30, 10, 60, 16);
	m_pszTextBoxTranslation[0]->setGUIObserver(this);
	m_pszTextBoxTranslation[1] = new geTextBox("Y", fontManager);
	m_pszTextBoxTranslation[1]->create(renderer, this, "0.0", 105, 10, 60, 16);
	m_pszTextBoxTranslation[1]->setGUIObserver(this);
	m_pszTextBoxTranslation[2] = new geTextBox("Z", fontManager);
	m_pszTextBoxTranslation[2]->create(renderer, this, "0.0", 180, 10, 60, 16);
	m_pszTextBoxTranslation[2]->setGUIObserver(this);

	m_pszTextBoxRotation[0] = new geTextBox("X", fontManager);
	m_pszTextBoxRotation[0]->create(renderer, this, "0.0", 30, 30, 60, 16);
	m_pszTextBoxRotation[0]->setGUIObserver(this);
	m_pszTextBoxRotation[1] = new geTextBox("Y", fontManager);
	m_pszTextBoxRotation[1]->create(renderer, this, "0.0", 105, 30, 60, 16);
	m_pszTextBoxRotation[1]->setGUIObserver(this);
	m_pszTextBoxRotation[2] = new geTextBox("Z", fontManager);
	m_pszTextBoxRotation[2]->create(renderer, this, "0.0", 180, 30, 60, 16);
	m_pszTextBoxRotation[2]->setGUIObserver(this);

	m_pszTextBoxScale[0] = new geTextBox("X", fontManager);
	m_pszTextBoxScale[0]->create(renderer, this, "0.0", 30, 50, 60, 16);
	m_pszTextBoxScale[0]->setGUIObserver(this);
	m_pszTextBoxScale[1] = new geTextBox("Y", fontManager);
	m_pszTextBoxScale[1]->create(renderer, this, "0.0", 105, 50, 60, 16);
	m_pszTextBoxScale[1]->setGUIObserver(this);
	m_pszTextBoxScale[2] = new geTextBox("Z", fontManager);
	m_pszTextBoxScale[2]->create(renderer, this, "0.0", 180, 50, 60, 16);
	m_pszTextBoxScale[2]->setGUIObserver(this);


	//window column
	geWindowColumn* pWindowColumn = new geWindowColumn(fontManager);
	pWindowColumn->create(m_pRenderer, this, 10, 350.0f, 10.0f, 0.07f);
	stWindowColumnRow* row = pWindowColumn->addRow("T");
	pWindowColumn->addControl(row, m_pszTextBoxTranslation[0], 18.0f);
	pWindowColumn->addControl(row, m_pszTextBoxTranslation[1], 18.0f);
	pWindowColumn->addControl(row, m_pszTextBoxTranslation[2], 18.0f);

	row = pWindowColumn->addRow("R");
	pWindowColumn->addControl(row, m_pszTextBoxRotation[0], 18.0f);
	pWindowColumn->addControl(row, m_pszTextBoxRotation[1], 18.0f);
	pWindowColumn->addControl(row, m_pszTextBoxRotation[2], 18.0f);

	row = pWindowColumn->addRow("S");
	pWindowColumn->addControl(row, m_pszTextBoxScale[0], 18.0f);
	pWindowColumn->addControl(row, m_pszTextBoxScale[1], 18.0f);
	pWindowColumn->addControl(row, m_pszTextBoxScale[2], 18.0f);
	//

	setNodeColor(0.21f, 0.21f, 0.21f);
	setNodeSelectionColor(0.21f, 0.21f, 0.21f);
	setClientAreaPrimaryActiveForeColor(0.21f, 0.21f, 0.21f, 1.0f);
	applyPrimaryColorToVBClientArea();
}
Example #10
0
int16 Op_SetNodeColor() {
	int16 color = popVar();
	int16 node = popVar();

	return setNodeColor(node, color);
}
Example #11
0
void Properties::onNodeDeselected() {
    setNodeLevel(-1);
    setNodeIndex(-1);
    setNodeColor(QColor());
}
Example #12
0
void Properties::onNodeSelected(int level, int index, const QColor& color) {
    setNodeLevel(level);
    setNodeIndex(index);
    setNodeColor(color);
}
void display_arm(){
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();

	glTranslatef(100, 100, 100);
	glRotatef(arm.Shoulder.Angle, 0, 0, 1);
	setNodeColor(0);
	wireBox(arm.Shoulder.Length, arm.Shoulder.Side);

	glTranslatef(arm.Shoulder.Length, 0, 0);
	glRotatef(arm.Forearm.Angle, 0, 0, 1);
	setNodeColor(1);
	wireBox(arm.Forearm.Length, arm.Forearm.Side);

	glTranslatef(arm.Forearm.Length, 0, 0);
	glRotatef(arm.Wrist.Angle, 1, 0, 0);
	setNodeColor(2);
	wireBox(arm.Wrist.Length, arm.Wrist.Side);

	glPushMatrix();
	glTranslatef(arm.Wrist.Length, -arm.Wrist.Side/2.0 + arm.f0_node0.Side/2.0, 0);
	glRotatef(arm.f0_node0.Angle, 0, 0, 1);
	setNodeColor(3);
	wireBox(arm.f0_node0.Length, arm.f0_node0.Side);

	glTranslatef(arm.f0_node0.Length, 0, 0);
	glRotatef(arm.f0_node1.Angle, 0, 0, 1);
	setNodeColor(4);
	wireBox(arm.f0_node1.Length, arm.f0_node1.Side);
	glPopMatrix();

	glPushMatrix();
	glTranslatef(arm.Wrist.Length, arm.Wrist.Side/2.0 - arm.f1_node0.Side/2.0, -arm.Wrist.Side/2.0 + arm.f1_node0.Side/2.0);
	glRotatef(-arm.f1_node0.Angle, 0, 0, 1);
	setNodeColor(5);
	wireBox(arm.f1_node0.Length, arm.f1_node0.Side);

	glTranslatef(arm.f1_node0.Length, 0, 0);
	glRotatef(-arm.f1_node1.Angle, 0, 0, 1);
	setNodeColor(6);
	wireBox(arm.f1_node1.Length, arm.f1_node1.Side);
	glPopMatrix();

	glPushMatrix();
	glTranslatef(arm.Wrist.Length, arm.Wrist.Side/2.0 - arm.f2_node0.Side/2.0, 0);
	glRotatef(-arm.f2_node0.Angle, 0, 0, 1);
	setNodeColor(7);
	wireBox(arm.f2_node0.Length, arm.f2_node0.Side);

	glTranslatef(arm.f2_node0.Length, 0, 0);
	glRotatef(-arm.f2_node1.Angle, 0, 0, 1);
	setNodeColor(8);
	wireBox(arm.f2_node1.Length, arm.f2_node1.Side);
	glPopMatrix();

	glPushMatrix();
	glTranslatef(arm.Wrist.Length, arm.Wrist.Side/2.0 - arm.f3_node0.Side/2.0, arm.Wrist.Side/2.0 - arm.f3_node0.Side/2.0);
	glRotatef(-arm.f3_node0.Angle, 0, 0, 1);
	setNodeColor(9);
	wireBox(arm.f3_node0.Length, arm.f3_node0.Side);

	glTranslatef(arm.f3_node0.Length, 0, 0);
	glRotatef(-arm.f3_node1.Angle, 0, 0, 1);
	setNodeColor(10);
	wireBox(arm.f3_node1.Length, arm.f3_node1.Side);
	glPopMatrix();

	glPopMatrix();
}