osgToy::OctoStrip::OctoStrip() { osg::Vec3Array* vAry = dynamic_cast<osg::Vec3Array*>( getVertexArray() ); osg::Vec3Array* nAry = dynamic_cast<osg::Vec3Array*>( getNormalArray() ); setNormalBinding( osg::Geometry::BIND_PER_VERTEX ); osg::Vec4Array* cAry = dynamic_cast<osg::Vec4Array*>( getColorArray() ); setColorBinding( osg::Geometry::BIND_PER_VERTEX ); osg::Vec3 xp( 1, 0, 0); osg::Vec4 red(1,0,0,1); osg::Vec3 xn(-1, 0, 0); osg::Vec4 cyan(0,1,1,1); osg::Vec3 yp( 0, 1, 0); osg::Vec4 green(0,1,0,1); osg::Vec3 yn( 0,-1, 0); osg::Vec4 magenta(1,0,1,1); osg::Vec3 zp( 0, 0, 1); osg::Vec4 blue(0,0,1,1); osg::Vec3 zn( 0, 0,-1); osg::Vec4 yellow(1,1,0,1); vAry->push_back(zp); nAry->push_back(zp); cAry->push_back(blue); vAry->push_back(yp); nAry->push_back(yp); cAry->push_back(green); vAry->push_back(xn); nAry->push_back(xn); cAry->push_back(cyan); vAry->push_back(zn); nAry->push_back(zn); cAry->push_back(yellow); vAry->push_back(yn); nAry->push_back(yn); cAry->push_back(magenta); vAry->push_back(xp); nAry->push_back(xp); cAry->push_back(red); vAry->push_back(zp); nAry->push_back(zp); cAry->push_back(blue); vAry->push_back(yp); nAry->push_back(yp); cAry->push_back(green); addPrimitiveSet( new osg::DrawArrays( GL_TRIANGLE_STRIP, 0, vAry->size() ) ); }
void RouteMapOverlay::RenderIsoRoute(IsoRoute *r, wxColour &grib_color, wxColour &climatology_color, wrDC &dc, PlugIn_ViewPort &vp) { SkipPosition *s = r->skippoints; if(!s) return; wxColour grib_deficient_color = TransparentColor(grib_color); wxColour climatology_deficient_color = TransparentColor(climatology_color); Position *p = s->point; wxColour *pcolor = &PositionColor(p, grib_color, climatology_color, grib_deficient_color, climatology_deficient_color); if(!dc.GetDC()) glBegin(GL_LINES); do { wxColour &ncolor = PositionColor(p->next, grib_color, climatology_color, grib_deficient_color, climatology_deficient_color); if(!p->copied || !p->next->copied) DrawLine(p, *pcolor, p->next, ncolor, dc, vp); pcolor = &ncolor; p = p->next; } while(p != s->point); if(!dc.GetDC()) glEnd(); /* now render any children */ wxColour cyan(0, 255, 255), magenta(255, 0, 255); for(IsoRouteList::iterator it = r->children.begin(); it != r->children.end(); ++it) RenderIsoRoute(*it, cyan, magenta, dc, vp); }
void LineSegment2I::TestDraw( ) { Color3B gray( 100, 100, 100 ); Color3B yellow( 255, 255, 0 ); Color3B magenta( 255, 0, 255 ); Color3B cyan( 0, 255, 255 ); int x = 60; int y = 20; int dx = 100; int dy = 80; LineSegment2I ln1( x, y, dx, dy ); int x1 = 160; int y1 = 20; int x2 = 60; int y2 = 100; LineSegment2I ln2( Point2I( x1, y1 ), Point2I( x2, y2 ) ); Rectangle oldClip = Surface::Current()->ClippingRect(); ln1.Draw( gray ); ln2.Draw( gray ); Surface::Current()->SetClippingRect( Rectangle( 100, 50, 20, 20 ) ); ln1.Draw( yellow ); ln2.Draw( yellow ); Surface::Current()->SetClippingRect( Rectangle( 60, 10, 20, 200 ) ); ln1.Draw( cyan ); ln2.Draw( cyan ); Surface::Current()->SetClippingRect( Rectangle( 140, 10, 20, 200 ) ); ln1.Draw( magenta ); ln2.Draw( magenta ); Surface::Current()->SetClippingRect( oldClip ); }
bool TriangleGame::loadContent() { vertexShader.reset(device->createVertexShader("TriangleShader.fx", "VS_Main", "vs_4_0")); vector<InputElementDescriptor> inputElements; inputElements.push_back(InputElementDescriptor("POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, true, 0)); inputElements.push_back(InputElementDescriptor("COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, true, 0)); inputLayout.reset(device->createInputLayout(inputElements, vertexShader.get())); pixelShader.reset(device->createPixelShader("TriangleShader.fx", "PS_Main", "ps_4_0")); float minX = -0.5f; float maxX = 0.5f; float minY = -1.0f; float maxY = 1.0f; XMFLOAT4 red(1.0f, 0.0f, 0.0f, 1.0f); XMFLOAT4 green(0.0f, 1.0f, 0.0f, 1.0f); XMFLOAT4 blue(0.0f, 0.0f, 1.0f, 1.0f); XMFLOAT4 yellow(1.0f, 1.0f, 0.0f, 1.0f); XMFLOAT4 cyan(0.0f, 1.0f, 1.0f, 1.0f); XMFLOAT4 magenta(1.0f, 0.0f, 1.0f, 1.0f); XMFLOAT4 white(1.0f, 1.0f, 1.0f, 1.0f); vector<Vertex> vertices; vertices.push_back(Vertex(XMFLOAT3(minX, maxY, 0.5f), red)); vertices.push_back(Vertex(XMFLOAT3(maxX, maxY, 0.5f), green)); vertices.push_back(Vertex(XMFLOAT3(minX, 0.0f, 0.5f), blue)); vertices.push_back(Vertex(XMFLOAT3(maxX, 0.0f, 0.5f), yellow)); vertices.push_back(Vertex(XMFLOAT3(minX, minY, 0.5f), cyan)); vertices.push_back(Vertex(XMFLOAT3(maxX, minY, 0.5f), magenta)); vertexBuffer.reset(device->createVertexBuffer(vertices.size() * sizeof(Vertex), &vertices[0])); return true; }
int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int show_mode) { std::string input_filename = select_input_file(hinst); read_image(input_filename, input_image); magenta(); std::string output_filename = boost::filesystem::basename(input_filename) + std::string("-magenta.png"); boost::gil::png_write_view(output_filename, boost::gil::const_view(output_image)); return 0; }
int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int show_mode) { std::string input_filename = select_input_file(hinst); read_image(input_filename, input_image); magenta(input_image, magenta_image); boost::gil::png_write_view(boost::filesystem::basename(input_filename) + std::string("-magenta.png"), boost::gil::const_view(magenta_image)); coarse_graining(magenta_image, coarse_image); boost::gil::png_write_view(boost::filesystem::basename(input_filename) + std::string("-magenta-coarse.png"), boost::gil::const_view(coarse_image)); detect_bottom_pixels(coarse_image); boost::gil::png_write_view(boost::filesystem::basename(input_filename) + std::string("-magenta-coarse-bottom.png"), boost::gil::const_view(coarse_image)); double slope; int x, y; boost::tie(slope, x, y) = detect_slope(coarse_image); std::string slope_str = boost::lexical_cast<std::string>(slope); ::MessageBox(NULL, multi_to_wide(slope_str).c_str(), L"slope", MB_OK); boost::gil::rgb8_view_t::xy_locator loc = boost::gil::view(coarse_image).xy_at(0, 0); if (slope > 0.0) { int xx = x; for (int i = xx + 1; i > 0; --i, --xx) { int yy = y + static_cast<int>((xx - x)*slope); if (0 <= yy && yy < coarse_image.height()) loc(xx, yy) = black_pixel; } } else { for (int xx = x; xx < coarse_image.width(); ++xx) { loc(xx, y + (xx - x)*slope) = boost::gil::rgb8_pixel_t(0, 0, 0); int yy = y + static_cast<int>((xx - x)*slope); if (0 <= yy && yy < coarse_image.height()) loc(xx, yy) = black_pixel; } } boost::gil::png_write_view(boost::filesystem::basename(input_filename) + std::string("-magenta-coarse-bottom-x.png"), boost::gil::const_view(coarse_image)); return 0; }
/// <summary> /// Cuboid constructor, takes size in 3 axes and creates cuboid at origin. /// New cuboid constructor code based on a mesh object. /// <summary> /// <param name="SX">Size of cuboid in X direction</param> /// <param name="SY">Size of cuboid in Y direction</param> /// <param name="SZ">Size of cuboid in Z direction</param> Cuboid::Cuboid(double SX, double SY, double SZ) { float hSX=(float)SX/2, hSY=(float)SY/2, hSZ=(float)SZ/2; //half sizes //create a unit cube using the mesh helpers glm::vec3 p[] = { //front face glm::vec3( hSX, -hSY, hSZ), //0 glm::vec3( hSX, hSY, hSZ), //1 glm::vec3(-hSX, hSY, hSZ), //2 glm::vec3(-hSX, -hSY, hSZ), //3 //back face glm::vec3( hSX, -hSY, -hSZ), //4 glm::vec3( hSX, hSY, -hSZ), //5 glm::vec3(-hSX, hSY, -hSZ), //6 glm::vec3(-hSX, -hSY, -hSZ) //7 }; //add faces one at a time here glm::vec3 red(1.0,0.0,0.0); glm::vec3 green(0.0,1.0,0.0); glm::vec3 blue(0.0,0.0,1.0); glm::vec3 yellow(1.0,1.0,0.0); glm::vec3 cyan(0.0,1.0,1.0); glm::vec3 magenta(1.0,0.0,1.0); AddFace(p[0],p[1],p[2],red,red,red); //front AddFace(p[0],p[2],p[3],red,red,red); AddFace(p[4],p[5],p[1],blue,blue,blue); //right AddFace(p[4],p[1],p[0],blue,blue,blue); AddFace(p[1],p[5],p[6],green,green,green); //top AddFace(p[1],p[6],p[2],green,green,green); AddFace(p[3],p[2],p[6],cyan,cyan,cyan); //left AddFace(p[3],p[6],p[7],cyan,cyan,cyan); AddFace(p[4],p[0],p[3],magenta,magenta,magenta); //bottom AddFace(p[4],p[3],p[7],magenta,magenta,magenta); AddFace(p[7],p[6],p[5],yellow,yellow,yellow); //back AddFace(p[7],p[5],p[4],yellow,yellow,yellow); CreateBuffers(); }
osgToy::TetraStrip::TetraStrip() { osg::Vec3Array* vAry = dynamic_cast<osg::Vec3Array*>( getVertexArray() ); osg::Vec3Array* nAry = dynamic_cast<osg::Vec3Array*>( getNormalArray() ); setNormalBinding( osg::Geometry::BIND_PER_VERTEX ); osg::Vec4Array* cAry = dynamic_cast<osg::Vec4Array*>( getColorArray() ); setColorBinding( osg::Geometry::BIND_PER_VERTEX ); osg::Vec3 ppp( 1, 1, 1); osg::Vec4 white(1,1,1,1); osg::Vec3 nnp( -1, -1, 1); osg::Vec4 blue(0,0,1,1); osg::Vec3 pnn( 1, -1, -1); osg::Vec4 red(1,0,0,1); osg::Vec3 npn( -1, 1, -1); osg::Vec4 green(0,1,0,1); osg::Vec3 ppn( 1, 1, -1); osg::Vec4 yellow(1,1,0,1); osg::Vec3 pnp( 1, -1, 1); osg::Vec4 magenta(1,0,1,1); osg::Vec3 nnn( -1, -1, -1); osg::Vec4 black(0,0,0,1); osg::Vec3 npp( -1, 1, 1); osg::Vec4 cyan(0,1,1,1); #if 1 vAry->push_back(ppp); nAry->push_back(ppp); cAry->push_back(white); vAry->push_back(nnp); nAry->push_back(nnp); cAry->push_back(blue); vAry->push_back(pnn); nAry->push_back(pnn); cAry->push_back(red); vAry->push_back(npn); nAry->push_back(npn); cAry->push_back(green); vAry->push_back(ppp); nAry->push_back(ppp); cAry->push_back(white); vAry->push_back(nnp); nAry->push_back(nnp); cAry->push_back(blue); #else vAry->push_back(ppn); nAry->push_back(ppn); cAry->push_back(yellow); vAry->push_back(pnp); nAry->push_back(pnp); cAry->push_back(magenta); vAry->push_back(nnn); nAry->push_back(nnn); cAry->push_back(black); vAry->push_back(npp); nAry->push_back(npp); cAry->push_back(cyan); vAry->push_back(ppn); nAry->push_back(ppn); cAry->push_back(yellow); vAry->push_back(pnp); nAry->push_back(pnp); cAry->push_back(magenta); #endif addPrimitiveSet( new osg::DrawArrays( GL_TRIANGLE_STRIP, 0, vAry->size() ) ); }
//------------------------------------------------------------------------------ // serialize() -- print the value of this object to the output stream sout. //------------------------------------------------------------------------------ std::ostream& Cmy::serialize(std::ostream& sout, const int i, const bool slotsOnly) const { int j = 0; if ( !slotsOnly ) { sout << "( " << getFactoryName() << std::endl; j = 4; } indent(sout,i+j); sout << "cyan: " << cyan() << std::endl; indent(sout,i+j); sout << "magenta: " << magenta() << std::endl; indent(sout,i+j); sout << "yellow: " << yellow() << std::endl; if ( !slotsOnly ) { indent(sout,i); sout << ")" << std::endl; } return sout; }
void My_TestGLDrawing::InitTest() { _renderIndex = HdRenderIndex::New(&_renderDelegate); TF_VERIFY(_renderIndex != nullptr); _delegate = new Hdx_UnitTestDelegate(_renderIndex); _delegate->SetRefineLevel(_refineLevel); // prepare render task SdfPath renderSetupTask("/renderSetupTask"); SdfPath renderTask("/renderTask"); _delegate->AddRenderSetupTask(renderSetupTask); _delegate->AddRenderTask(renderTask); // render task parameters. HdxRenderTaskParams param = _delegate->GetTaskParam( renderSetupTask, HdTokens->params).Get<HdxRenderTaskParams>(); param.enableLighting = true; // use default lighting _delegate->SetTaskParam(renderSetupTask, HdTokens->params, VtValue(param)); _delegate->SetTaskParam(renderTask, HdTokens->collection, VtValue(HdRprimCollection(HdTokens->geometry, _reprName))); // prepare scene // To ensure that the non-aggregated element index returned via picking, // we need to have at least two cubes with uniform colors. GfVec4f red(1,0,0,1), green(0,1,0,1), blue(0,0,1,1), yellow(1,1,0,1), magenta(1,0,1,1), cyan(0,1,1,1), white(1,1,1,1), black(0,0,0,1); GfVec4f faceColors[] = { red, green, blue, yellow, magenta, cyan}; VtValue faceColor = VtValue(_BuildArray(&faceColors[0], sizeof(faceColors)/sizeof(faceColors[0]))); GfVec4f vertColors[] = { white, blue, green, yellow, black, blue, magenta, red}; VtValue vertColor = VtValue(_BuildArray(&vertColors[0], sizeof(vertColors)/sizeof(vertColors[0]))); _delegate->AddCube(SdfPath("/cube0"), _GetTranslate( 5, 0, 5), /*guide=*/false, /*instancerId=*/SdfPath(), /*scheme=*/PxOsdOpenSubdivTokens->catmark, /*color=*/faceColor, /*colorInterpolation=*/Hdx_UnitTestDelegate::UNIFORM); _delegate->AddCube(SdfPath("/cube1"), _GetTranslate(-5, 0, 5), /*guide=*/false, /*instancerId=*/SdfPath(), /*scheme=*/PxOsdOpenSubdivTokens->catmark, /*color=*/faceColor, /*colorInterpolation=*/Hdx_UnitTestDelegate::UNIFORM); _delegate->AddCube(SdfPath("/cube2"), _GetTranslate(-5, 0,-5)); _delegate->AddCube(SdfPath("/cube3"), _GetTranslate( 5, 0,-5), /*guide=*/false, /*instancerId=*/SdfPath(), /*scheme=*/PxOsdOpenSubdivTokens->catmark, /*color=*/vertColor, /*colorInterpolation=*/Hdx_UnitTestDelegate::VERTEX); { _delegate->AddInstancer(SdfPath("/instancerTop")); _delegate->AddCube(SdfPath("/protoTop"), GfMatrix4d(1), false, SdfPath("/instancerTop")); std::vector<SdfPath> prototypes; prototypes.push_back(SdfPath("/protoTop")); VtVec3fArray scale(3); VtVec4fArray rotate(3); VtVec3fArray translate(3); VtIntArray prototypeIndex(3); scale[0] = GfVec3f(1); rotate[0] = GfVec4f(0); translate[0] = GfVec3f(3, 0, 2); prototypeIndex[0] = 0; scale[1] = GfVec3f(1); rotate[1] = GfVec4f(0); translate[1] = GfVec3f(0, 0, 2); prototypeIndex[1] = 0; scale[2] = GfVec3f(1); rotate[2] = GfVec4f(0); translate[2] = GfVec3f(-3, 0, 2); prototypeIndex[2] = 0; _delegate->SetInstancerProperties(SdfPath("/instancerTop"), prototypeIndex, scale, rotate, translate); } { _delegate->AddInstancer(SdfPath("/instancerBottom")); _delegate->AddCube(SdfPath("/protoBottom"), GfMatrix4d(1), false, SdfPath("/instancerBottom")); std::vector<SdfPath> prototypes; prototypes.push_back(SdfPath("/protoBottom")); VtVec3fArray scale(3); VtVec4fArray rotate(3); VtVec3fArray translate(3); VtIntArray prototypeIndex(3); scale[0] = GfVec3f(1); rotate[0] = GfVec4f(0); translate[0] = GfVec3f(3, 0, -2); prototypeIndex[0] = 0; scale[1] = GfVec3f(1); rotate[1] = GfVec4f(0); translate[1] = GfVec3f(0, 0, -2); prototypeIndex[1] = 0; scale[2] = GfVec3f(1); rotate[2] = GfVec4f(0); translate[2] = GfVec3f(-3, 0, -2); prototypeIndex[2] = 0; _delegate->SetInstancerProperties(SdfPath("/instancerBottom"), prototypeIndex, scale, rotate, translate); } SetCameraTranslate(GfVec3f(0, 0, -20)); // XXX: Setup a VAO, the current drawing engine will not yet do this. glGenVertexArrays(1, &vao); glBindVertexArray(vao); glBindVertexArray(0); }
SynthRenderResult SynthRenderer::render(AppState &state, const Scene &s, const Cameraf &c, bool qualityEstimateOnly) { D3D11RenderTarget &renderTarget = qualityEstimateOnly ? renderTargetSmall : renderTargetBig; Bitmap occludedObjectColor, unoccludedObjectColor; // // unoccluded rendering // renderTarget.bind(); renderTarget.clear(vec4f(1.0f, 0.0f, 1.0f, 1.0f)); s.objects[s.mainObjectIndex].render(state, c); renderTarget.captureColorBuffer(unoccludedObjectColor); // // occluded rendering // renderTarget.bind(); renderTarget.clear(vec4f(1.0f, 0.0f, 1.0f, 1.0f)); for (UINT objectIndex = 0; objectIndex < s.objects.size(); objectIndex++) { if (objectIndex != s.mainObjectIndex) s.objects[objectIndex].render(state, c); } renderTarget.clearColor(vec4f(1.0f, 0.0f, 1.0f, 1.0f)); s.objects[s.mainObjectIndex].render(state, c); renderTarget.captureColorBuffer(occludedObjectColor); state.graphics->bindRenderTarget(); SynthRenderResult result; if (!qualityEstimateOnly) { result.occludedObjectColor = occludedObjectColor; } ml::vec4uc magenta(255, 0, 255, 255); auto countPixels = [&](const Bitmap &image) { size_t count = 0; for (const auto &p : image) if (p.value != magenta) count++; return count; }; auto borderClear = [&](const Bitmap &image) { for (int y = 0; y < (int)image.getHeight(); y++) if (image(y, 0) != magenta || image(y, (int)image.getWidth() - 1) != magenta) return false; for (int x = 0; x < (int)image.getWidth(); x++) if (image(0, x) != magenta || image((int)image.getHeight() - 1, x) != magenta) return false; return true; }; double occlusionPercentage = 0.0; double totalScreenCoverage = 0.0; const size_t occludedObjectPixels = countPixels(occludedObjectColor); const size_t totalObjectPixels = countPixels(unoccludedObjectColor); double borderQuality = 0.0; if (borderClear(unoccludedObjectColor)) { borderQuality = 1.0; } result.quality = 0.0; if (totalObjectPixels > 0) { occlusionPercentage = 1.0 - (double)occludedObjectPixels / (double)totalObjectPixels; totalScreenCoverage = (double)occludedObjectPixels / double(occludedObjectColor.getNumPixels()); const int minTotalPixelCount = 1000; const float maxOcclusionPercentage = 0.4; const float minScreenCoverage = 0.15; const float maxScreenCoverage = 0.7; if (occludedObjectPixels >= minTotalPixelCount && occlusionPercentage <= maxOcclusionPercentage && totalScreenCoverage >= minScreenCoverage && totalScreenCoverage <= maxScreenCoverage && borderQuality > 0.0) { // TODO: this is not a good metric because it favors unoccluded too much... //result.quality = ml::math::max(totalScreenCoverage, 0.1); result.quality = 1.0; } } const ModelInstance &object = s.objects[s.mainObjectIndex]; //const vec3f objectCenter = object.modelToWorld * object.object.model->bbox.getCenter(); //const vec3f objectFrameX = (object.modelToWorld * (object.object.model->bbox.getCenter() + vec3f::eX) - objectCenter).getNormalized(); //const vec3f objectFrameY = (object.modelToWorld * (object.object.model->bbox.getCenter() + vec3f::eY) - objectCenter).getNormalized(); //const vec3f objectFrameZ = (object.modelToWorld * (object.object.model->bbox.getCenter() + vec3f::eZ) - objectCenter).getNormalized(); result.camera = c; result.annotations.push_back("modelName=" + object.model->modelName); result.annotations.push_back("modelCategory=" + object.model->categoryName); result.annotations.push_back("cameraEye=" + c.getEye().toString()); result.annotations.push_back("cameraRight=" + c.getRight().toString()); result.annotations.push_back("cameraLook=" + c.getLook().toString()); result.annotations.push_back("occludedObjectPixels=" + std::to_string(occludedObjectPixels)); result.annotations.push_back("totalObjectPixels=" + std::to_string(totalObjectPixels)); result.annotations.push_back("occlusionPercentage=" + std::to_string(occlusionPercentage)); result.annotations.push_back("totalScreenCoverage=" + std::to_string(totalScreenCoverage)); result.annotations.push_back("borderQuality=" + std::to_string(borderQuality)); result.annotations.push_back("quality=" + std::to_string(result.quality)); return result; }