コード例 #1
0
ファイル: ofxAVUIDropDown.cpp プロジェクト: AVUIs/ofxAVUI
void ofxAVUIDropDown::draw(){
    float padding = ofGetHeight()/150;
    if (takeover && takeoverShape.x==0 && takeoverShape.y==0 && takeoverShape.width==0 && takeoverShape.height==0) {
        cout << "WARNING: Takeover not possible without zone.update() invoked before zone.draw()" << endl;
        takeover = false;
    } else if (takeover) {
        ofPushStyle();
        ofSetColor(bgColor);
        ofDrawRectangle(takeoverShape.x,takeoverShape.y,takeoverShape.width,takeoverShape.height);
        ofSetColor(fgColor);
        drawContour();
        //current selection if any
        int mid = itemHeight/2 + (customFont ? uifont->getStringBoundingBox("1",0,0).height : getBitmapStringBoundingBox("1").height) / 2;
        if (selection!=-1)  {
            if (!customFont) ofDrawBitmapString(fitString("< " + items[selection]), takeoverShape.x + 5, (topPositionSpecial?(shape.y + shape.height - 5):(takeoverShape.y + mid)));
                else uifont->drawString(fitString("< " + items[selection]), takeoverShape.x + padding, (topPositionSpecial?(shape.y + shape.height - padding):(takeoverShape.y + mid)));
            if (!topPositionSpecial) {  //draw top line if not top of the zone
                ofDrawLine(takeoverShape.x, takeoverShape.y + itemHeight, takeoverShape.x + takeoverShape.width*0.25, takeoverShape.y + itemHeight);
                ofDrawLine(takeoverShape.x + takeoverShape.width*0.75, takeoverShape.y + itemHeight, takeoverShape.x + takeoverShape.width, takeoverShape.y + itemHeight);
            }
            //other items in current page
            int itemsCount = itemsPerPage;
            if ((currentPage==numPages-1) && items.size()%itemsPerPage > 0) itemsCount = items.size()%itemsPerPage;
            for(std::size_t i = 0; i < itemsCount; i++){
                if (!customFont) ofDrawBitmapString(items[i+currentPage*itemsPerPage], takeoverShape.x + 5, takeoverShape.y + (i+1)*itemHeight+mid);
                    else uifont->drawString(items[i+currentPage*itemsPerPage], takeoverShape.x + padding, takeoverShape.y + (i+1)*itemHeight+mid);
//            ofDrawLine(takeoverShape.x, takeoverShape.y + (i+2)*itemHeight, takeoverShape.x + takeoverShape.width*0.25, takeoverShape.y + (i+2)*itemHeight);
//            ofDrawLine(takeoverShape.x + takeoverShape.width*0.75, takeoverShape.y + (i+2)*itemHeight, takeoverShape.x + takeoverShape.width, takeoverShape.y + (i+2)*itemHeight);
            }
        }
        //pages nav
//        ofDrawLine(takeoverShape.x, takeoverShape.y + (itemsPerPage+1)*itemHeight, takeoverShape.x + shape.width, takeoverShape.y + (itemsPerPage+1)*itemHeight);
        ofDrawLine(takeoverShape.x, takeoverShape.y + (itemsPerPage+1)*itemHeight, takeoverShape.x + takeoverShape.width*0.25, takeoverShape.y + (itemsPerPage+1)*itemHeight);
        ofDrawLine(takeoverShape.x + takeoverShape.width*0.75, takeoverShape.y + (itemsPerPage+1)*itemHeight, takeoverShape.x + takeoverShape.width, takeoverShape.y + (itemsPerPage+1)*itemHeight);
        if (!customFont) ofDrawBitmapString("<", takeoverShape.x + 15, takeoverShape.y + (itemsPerPage+1)*itemHeight + mid);
            else uifont->drawString("<", takeoverShape.x + padding*3, takeoverShape.y + (itemsPerPage+1)*itemHeight + mid);
        if (!customFont) ofDrawBitmapString(">", takeoverShape.x + takeoverShape.width-15-getBitmapStringBoundingBox(">").width, takeoverShape.y + (itemsPerPage+1)*itemHeight + mid);
            else uifont->drawString(">", takeoverShape.x + takeoverShape.width-padding*3-uifont->getStringBoundingBox(">",0,0).width, takeoverShape.y + (itemsPerPage+1)*itemHeight + mid);
        if (!customFont) ofDrawBitmapString(ofToString(currentPage+1)+"/"+ofToString(numPages), takeoverShape.x + (takeoverShape.width-getBitmapStringBoundingBox("8/8").width)/2, takeoverShape.y + (itemsPerPage+1)*itemHeight + mid);
            else uifont->drawString(ofToString(currentPage+1)+"/"+ofToString(numPages), takeoverShape.x + (takeoverShape.width-uifont->getStringBoundingBox("8/8",0,0).width)/2, takeoverShape.y + (itemsPerPage+1)*itemHeight + mid);
        ofPopStyle();
    } else {
        ofPushStyle();
        ofSetColor(bgColor);
        ofDrawRectangle(shape.x,shape.y,shape.width,shape.height);
        ofSetColor(fgColor);
        drawContour();
//        drawTitle();
        if (selection!=-1) {
            if (!customFont) ofDrawBitmapString(fitString("> " + items[selection]), shape.x + 5, shape.y + shape.height - 5);
                else uifont->drawString(fitString("> " + items[selection]), shape.x + padding, shape.y + shape.height - padding);
        }
        ofPopStyle();
    }
}
コード例 #2
0
ファイル: BlackBoxApp.cpp プロジェクト: grifotv/blackbox
void BlackBoxApp::draw() {
	toogleRGB();
	
	if(noEffects) return;
		
	ofPushMatrix();
	ofTranslate(ofGetWidth() / 2, ofGetHeight() / 2);
	
	switch (drawMethod) {
		case 1:
			rotationPointCloud += (kbControlEase - rotationPointCloud)/ease;
			ofRotateY(rotationPointCloud);
			
			zoom += (kbZoom - zoom) / ease;
			ofScale(400 * zoom, 400 * zoom, 400 * zoom);
			drawPointCloud();
			break;
			
		case 2:
			zoom += (kbZoom - zoom) / ease;
			ofScale(400 * zoom, 400 * zoom, 400 * zoom);
			drawCircleCloud();
			break;
			
		case 3:
			ofScale(400, 400, 400);
			drawParticlesCloud();
			break;
			
		case 4:
			ofScale(1000, 1000, 1000);
			drawPixels();
			break;
			
		case 5:
			drawTriangleLines();
			break;
			
		case 6:
			drawLaser();
			break;
			
		case 7:
			drawContour();
			break;
			
		case 8:
			drawTriangleColor();
			break;
			
		case 9:
			drawTriangleBlue();
			break;
	}
	
	ofPopMatrix();
	
	ofSetColor(255, 255, 255);
	string showrgbString = "showRGB: "+ofToString(showRGB, 2);
}
コード例 #3
0
ファイル: main.c プロジェクト: ntavish/tri
void draw(int dummy)
{
	//delaunay
	cvClearMemStorage(storage);
	subdiv=cvCreateSubdivDelaunay2D(rect,trianglestore);

	blur(origV, out);
	SWAP(in,out);
	thresh(in, out);
	findContours(out, storage, &contours);

	cvMerge(origH, origS, out, NULL, temp);
	cvCvtColor( temp, temp, CV_HSV2RGB );

	every_contour(contours, temp);
	drawContour(temp, contours);
	SWAP(in,out);

	draw_subdiv(temp,subdiv, cvScalar(255,255,255,255));
		if(k==0)
		{
		cvNot(in,out);
		//k=1;
		}
		else{}
	cvClearMemStorage(trianglestore);
	//findcorners(origH,out);   //needs 32bit float image

	cvShowImage(OUT, temp);
}
コード例 #4
0
ファイル: ofxAVUISlider.cpp プロジェクト: berkan/ofxAVUI
void ofxAVUISlider::draw(){
//this is here so we dont need to call update() every cycle
//    if (clicking && (ofGetElapsedTimeMillis() - doubleClickTimer > DOUBLECLICK_MILLIS)) {
//        x = mouseArgs.x;
//        ofParameter<float>  p1 = soundProperties->getFloat(param1);
//        float horizVal = ofMap(x, shape.x, shape.x + shape.width, p1.getMin(), p1.getMax());
//        p1 = horizVal;
//        clicking = false;
//    }
    if (synced) update();
    ofPushStyle();
    ofSetColor(bgColor);
    ofDrawRectangle(0,0,shape.width,shape.height);
    ofSetColor(fgColor);
    ofNoFill();
    drawContour();
    drawTitle();
    ofDrawLine(x-shape.x, 0, x-shape.x, shape.height);  //cursor
    if(soundProperties->getBool(paramBoolToggle)) ofDrawCircle(x - shape.x, shape.height/2,10); //draw toggle
    ofPopStyle();
}
コード例 #5
0
ファイル: FindQuads.cpp プロジェクト: TimDekiere/chilitags
void chilitags::FindQuads::run()
{
	//TODO function too long, split it

	mQuads.clear();
	const cv::Mat tBinaryImage = *mBinaryImage;
#ifdef DEBUG_FindQuads
	cv::RNG tRNG( 0xFFFFFFFF );
	cv::Mat tDebugImage = cv::Mat::zeros(cv::Size(2*tBinaryImage.cols, tBinaryImage.rows), CV_8UC3);
#endif

	mScaledCopies[0] = tBinaryImage;
	for (int i = 1; i < scScaledCopiesCount; ++i) {
		cv::pyrDown(mScaledCopies[i-1], mScaledCopies[i]);
	}

	for (int i = scScaledCopiesCount-1; i>=0; --i) //starting with the lowest definition, so the highest definition are last, and can simply override the first ones.
	{
		int tScale = 1 << i;
#ifdef DEBUG_FindQuads
		cv::Point tOffset(tDebugImage.cols-2*mScaledCopies[i].cols,0);
		cv::Size tScaledSize = mScaledCopies[i].size();
#endif
		std::vector<std::vector<cv::Point> > contours;
		cv::findContours(mScaledCopies[i], contours, cv::RETR_LIST, cv::CHAIN_APPROX_SIMPLE);

		for (std::vector<std::vector<cv::Point> >::iterator contour = contours.begin();
			contour != contours.end();
			++contour)
		{
			double tPerimeter = std::abs(cv::arcLength(*contour, true));
			double tArea = std::abs(cv::contourArea(*contour));

			if (tPerimeter > Quad::scNPoints*scMinTagSize && tArea > scMinTagSize*scMinTagSize)
			{
				std::vector<cv::Point> tApproxContour;
				cv::approxPolyDP( *contour, tApproxContour, tPerimeter*0.02, true);

				std::vector<cv::Point> tNormalisedContour;
				cv::convexHull(tApproxContour, tNormalisedContour, false);

				if (tNormalisedContour.size() == (int) Quad::scNPoints)
				{
					Quad tCandidate;
					tCandidate[0] = tScale*tNormalisedContour[0];
					tCandidate[1] = tScale*tNormalisedContour[1];
					tCandidate[2] = tScale*tNormalisedContour[2];
					tCandidate[3] = tScale*tNormalisedContour[3];

					IsSimilarTo tIsSimilarToCandidate(tCandidate);

					std::vector<Quad>::iterator tSameQuad = std::find_if(
						mQuads.begin(),
						mQuads.end(),
						tIsSimilarToCandidate);
					if (false && tSameQuad != mQuads.end()) // TODO move to Decode
					{
						*tSameQuad = tCandidate;
#ifdef DEBUG_FindQuads
						drawContour(tDebugImage, tNormalisedContour, cv::Scalar(0,255,255), tOffset);
#endif
					}
					else
					{
						mQuads.push_back(tCandidate);
#ifdef DEBUG_FindQuads
						drawContour(tDebugImage, tNormalisedContour, cv::Scalar(0,255,0), tOffset);
#endif
					}
				}
#ifdef DEBUG_FindQuads
				else // not quadrilaterals
				{
					drawContour(tDebugImage, tNormalisedContour, cv::Scalar(0,0,255), tOffset);
				}
#endif
			}
#ifdef DEBUG_FindQuads
			else // too small
			{
				drawContour(tDebugImage, *contour, cv::Scalar(128,128,128), tOffset);
			}
#endif
		}
#ifdef DEBUG_FindQuads
		cv::putText(tDebugImage, cv::format("%d", contours.size()), tOffset+cv::Point(32,32),
			cv::FONT_HERSHEY_SIMPLEX, 0.5, cv::Scalar::all(255));
#endif
	}
#ifdef DEBUG_FindQuads
	cv::imshow("FindQuads", tDebugImage);
	cv::waitKey(0);
#endif
}
コード例 #6
0
ファイル: FindQuads.cpp プロジェクト: geeksville/chilitags
std::vector<chilitags::Quad> chilitags::FindQuads::operator()(const cv::Mat &greyscaleImage)
{
    //TODO function too long, split it

    std::vector<Quad> quads;
#ifdef DEBUG_FindQuads
    cv::RNG rNG( 0xFFFFFFFF );
    cv::Mat debugImage = cv::Mat::zeros(
        cv::Size(2*greyscaleImage.cols, greyscaleImage.rows),
        CV_8UC3);
#endif

    // Resize the input image to make it at most mMaxInputWidth wide
    if (mMaxInputWidth > 0 && greyscaleImage.cols > mMaxInputWidth) {
        cv::resize(greyscaleImage, mGrayPyramid[0], cv::Size(mMaxInputWidth, greyscaleImage.rows*mMinInputWidth/greyscaleImage.cols), .0, .0, cv::INTER_NEAREST);
    } else {
        mGrayPyramid[0] = greyscaleImage;
    }

    // Subsample the possibly resized image by a factor two,
    // as long as the width is at least mMinInputWidth
    int nPyramidLevel = 1;
    if (mMinInputWidth > 0) {
        while (mGrayPyramid[nPyramidLevel-1].cols/2 >= mMinInputWidth) {
            if (nPyramidLevel >= mGrayPyramid.size()) mGrayPyramid.push_back(cv::Mat());
            cv::resize(mGrayPyramid[nPyramidLevel-1], mGrayPyramid[nPyramidLevel], cv::Size(), .5, .5, cv::INTER_NEAREST);
            ++nPyramidLevel;
        }
    }

    while (mBinaryPyramid.size() < nPyramidLevel) mBinaryPyramid.push_back(cv::Mat());
    for (int i = 0; i < nPyramidLevel; ++i) {
        cv::Canny(mGrayPyramid[i], mBinaryPyramid[i], 100, 200, 3);
    }

    for (int i = nPyramidLevel-1; i>=0; --i) //starting with the lowest definition, so the highest definition are last, and can simply override the first ones.
    {
        int scale = 1 << i;
#ifdef DEBUG_FindQuads
        cv::Point offset(debugImage.cols-2*mBinaryPyramid[i].cols,0);
        cv::rectangle(debugImage, cv::Rect(offset.x, offset.y, greyscaleImage.cols/scale, greyscaleImage.rows/scale), cv::Scalar::all(255));
#endif
        std::vector<std::vector<cv::Point> > contours;
        cv::findContours(mBinaryPyramid[i], contours, cv::RETR_LIST, cv::CHAIN_APPROX_SIMPLE);

        for (std::vector<std::vector<cv::Point> >::iterator contour = contours.begin();
             contour != contours.end();
             ++contour)
        {
            double perimeter = std::abs(cv::arcLength(*contour, true));
            double area = std::abs(cv::contourArea(*contour));

            if (perimeter > 4*MIN_TAG_SIZE && area > MIN_TAG_SIZE*MIN_TAG_SIZE)
            {
                cv::Mat approxContour;
                cv::approxPolyDP( *contour, approxContour, perimeter*0.05, true);

                cv::Mat normalisedContour;
                cv::convexHull(approxContour, normalisedContour, false);

                if (normalisedContour.rows == 4)
                {
#ifdef DEBUG_FindQuads
                    drawContour(debugImage, normalisedContour, cv::Scalar(0,255,0), offset);
#endif
                    normalisedContour *= scale;
                    quads.push_back(normalisedContour.reshape(1));
                }
#ifdef DEBUG_FindQuads
                else // not quadrilaterals
                {
                    drawContour(debugImage, normalisedContour, cv::Scalar(0,0,255), offset);
                }
#endif
            }
#ifdef DEBUG_FindQuads
            else // too small
            {
                //drawContour(debugImage, *contour, cv::Scalar(128,128,128), offset);
            }
#endif
        }
#ifdef DEBUG_FindQuads
        cv::putText(debugImage, cv::format("%d, %d", quads.size(), contours.size()), offset+cv::Point(32,32),
                    cv::FONT_HERSHEY_SIMPLEX, 0.5, cv::Scalar::all(255));
#endif
    }
#ifdef DEBUG_FindQuads
    cv::imshow("FindQuads", debugImage);
    cv::waitKey(0);
#endif

    return quads;
}
コード例 #7
0
ファイル: MapChunk.cpp プロジェクト: Ikesters/noggit
void MapChunk::draw()
{

	if (!gWorld->frustum.intersects(vmin, vmax))
		return;

	float mydist = (gWorld->camera - vcenter).length() - r;

	if (mydist > (mapdrawdistance * mapdrawdistance))
		return;

	// setup vertex buffers
	glBindBuffer(GL_ARRAY_BUFFER, vertices);
	glVertexPointer(3, GL_FLOAT, 0, 0);
	glBindBuffer(GL_ARRAY_BUFFER, normals);
	glNormalPointer(GL_FLOAT, 0, 0);
	// ASSUME: texture coordinates set up already

	// first pass: base texture
	if (textureSet->num() == 0U)
	{
		OpenGL::Texture::setActiveTexture(0);
		OpenGL::Texture::disableTexture();

		OpenGL::Texture::setActiveTexture(1);
		OpenGL::Texture::disableTexture();

		glColor3f(1.0f, 1.0f, 1.0f);
	}
	else
	{
		textureSet->bindTexture(0, 0);

		OpenGL::Texture::setActiveTexture(1);
		OpenGL::Texture::disableTexture();
	}

	glEnable(GL_LIGHTING);
	drawPass(-1);
	
	if (textureSet->num() > 1U) {
		//glDepthFunc(GL_EQUAL); // GL_LEQUAL is fine too...?
		glDepthMask(GL_FALSE);
	}

	// additional passes: if required
	for (size_t i = 1; i < textureSet->num(); ++i)
	{
		// this time, use blending:
		textureSet->bindTexture(i, 0);
		textureSet->bindAlphamap(i - 1, 1);

		drawPass(i);
	}

	if (textureSet->num() > 1U)
	{
		//glDepthFunc(GL_LEQUAL);
		glDepthMask(GL_TRUE);
	}

	// shadow map
	glActiveTexture(GL_TEXTURE0);
	glDisable(GL_TEXTURE_2D);
	glDisable(GL_LIGHTING);

	Vec3D shc = gWorld->skies->colorSet[WATER_COLOR_DARK] * 0.3f;
	glColor4f(shc.x, shc.y, shc.z, 1);

	//glColor4f(1,1,1,1);

	glActiveTexture(GL_TEXTURE1);
	glBindTexture(GL_TEXTURE_2D, shadow);
	glEnable(GL_TEXTURE_2D);

	drawPass(-1);

	glDisable(GL_TEXTURE_2D);
	glDisable(GL_LIGHTING);

	drawContour();

	if (terrainMode == 5)
	{
		// draw chunk white if impassible flag is set
		if (Flags & FLAG_IMPASS)
		{
			glColor4f(1, 1, 1, 0.6f);
			drawPass(-1);
		}
	}

	if (terrainMode == 6)
	{
		if (water)
		{
			glColor4f(0.2f, 0.2f, 0.8f, 0.6f);
			drawPass(-1);
		}
	}

	if (terrainMode == 4)
	{
		// draw chunks in color depending on AreaID and list color from environment
		if (Environment::getInstance()->areaIDColors.find(areaID) != Environment::getInstance()->areaIDColors.end())
		{
			Vec3D colorValues = Environment::getInstance()->areaIDColors.find(areaID)->second;
			glColor4f(colorValues.x, colorValues.y, colorValues.z, 0.7f);
			drawPass(-1);
		}
	}

	if (terrainMode == 8)
	{
		glBindBuffer(GL_ARRAY_BUFFER, mccvEntry);
		glColorPointer(4, GL_UNSIGNED_BYTE, 0, 0);

		glEnableClientState(GL_COLOR_ARRAY);
		drawPass(-1);
		glDisableClientState(GL_COLOR_ARRAY);
	}

	if (Environment::getInstance()->cursorType == 3)
	{
		if (gWorld->IsSelection(eEntry_MapChunk) && gWorld->GetCurrentSelection()->data.mapchunk == this && terrainMode != 3)
		{
			int poly = gWorld->GetCurrentSelectedTriangle();

			glColor4f(1.0f, 1.0f, 0.0f, 1.0f);

			glPushMatrix();

			glDisable(GL_CULL_FACE);
			glDepthMask(false);
			glDisable(GL_DEPTH_TEST);
			glBegin(GL_TRIANGLES);
			glVertex3fv(mVertices[gWorld->mapstrip2[poly + 0]]);
			glVertex3fv(mVertices[gWorld->mapstrip2[poly + 1]]);
			glVertex3fv(mVertices[gWorld->mapstrip2[poly + 2]]);
			glEnd();
			glEnable(GL_CULL_FACE);
			glEnable(GL_DEPTH_TEST);
			glDepthMask(true);

			glPopMatrix();
		}
	}


	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

	glEnable(GL_LIGHTING);
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
}