void VisitadorGP::visitData(const IData& d) { IShape* pS; d.getShape(&pS); // do something. Region r; pS->getMBR(r); // cout << "punto " << contador++ << ": " << r.m_pHigh[0] << " - " << r.m_pHigh[1] << endl; //cout << r.m_pHigh[0] << " " << r.m_pHigh[1] << endl; xy_pts_B.push_back(std::make_pair(r.m_pHigh[0], r.m_pHigh[1])); contador++; //cout<< "contador " << contador << endl; delete pS; // data should be an array of characters representing a Region as a string. byte* pData = 0; uint32_t cLen = 0; d.getData(cLen, &pData); // do something. //string s = reinterpret_cast<char*>(pData); //cout << s << endl; delete[] pData; //cout << d.getIdentifier() << endl; // the ID of this data entry is an answer to the query. I will just print it to stdout. }
IShape* NodeFactory::CreateTriangle(float width, float height, const Color4F& color) { ShapeTriangleMesh* mesh = MeshFactory::Instance().CreateShapeTriangleMesh(width, height, color); RETURN_NULL_IF_NULL(mesh); IMaterial* material = MaterialFactory::Instance().CreateShape(MEDUSA_PREFIX(Shape)); IShape* sprite = new IShape(); sprite->Initialize(); sprite->SetSizeToContent(SizeToContent::Mesh); sprite->SetMesh(mesh); sprite->SetMaterial(material); return sprite; }
bool inside_operator_variable::is_inside( const SpatialIndex::Point& p ) { tree_visitor v; m_rtree.point_location_query( p, v ); vector<unsigned int> result = v.get_query_result(); vector<unsigned int>::iterator i; bool inside = false; if ( m_type == geo_type::UNION ) { for ( i = result.begin(); i != result.end() ; i++ ) { IShape* s = m_regions[ ( *i ) ]; if ( s->containsShape( p ) || s->touchesShape( p ) ) { inside = true; break; } } } else if ( m_type == geo_type::INTERSECTION ) { if ( result.size() == m_regions.size() ) { bool loop_break = false; for ( i = result.begin(); i != result.end() ; i++ ) { IShape* s = m_regions[ ( *i ) ]; if ( !( s->containsShape( p ) ) && !( s->touchesShape( p ) ) ) { loop_break = true; break; } } inside = !loop_break; } } else { if ( result.size() == 0 ) { // nothing to do // inside was already set to false } else { IShape* s = m_regions[ 0 ]; if ( s->containsShape( p ) || s->touchesShape( p ) ) { inside = true; } } } return inside; }
IShape* NodeFactory::CreateCircle(float radius, float precision, const Color4F& color) { ShapeGeneralMesh* mesh = MeshFactory::Instance().CreateShapeCircleMesh(radius, precision, color); RETURN_NULL_IF_NULL(mesh); IMaterial* material = MaterialFactory::Instance().CreateShape(MEDUSA_PREFIX(Shape_TrianglesFan)); material->SetDrawMode(GraphicsDrawMode::TriangleFan); IShape* sprite = new IShape(); sprite->Initialize(); sprite->SetSizeToContent(SizeToContent::Mesh); sprite->SetMesh(mesh); sprite->SetMaterial(material); return sprite; }
IShape* NodeFactory::CreateTriangle(const Point3F& p1, const Point3F& p2, const Point3F& p3, const Color4F& color) { auto mesh = MeshFactory::Instance().CreateShapeTriangleMesh(p1, p2, p3, color); RETURN_NULL_IF_NULL(mesh); auto material = MaterialFactory::Instance().CreateShape(MEDUSA_PREFIX(Shape)); IShape* sprite = new IShape(); sprite->Initialize(); sprite->SetSizeToContent(SizeToContent::Mesh); sprite->SetMesh(mesh); sprite->SetMaterial(material); return sprite; }
std::unique_ptr<Intersection> Scene::intersect(const Ray& ray) const { IShape* nearestHit = nullptr; double t_min = std::numeric_limits<double>::max(); for(auto const& shape : _shapes) { assert(shape); double t = shape->intersect(ray); if(t < 0) continue; if(t > t_min) continue; t_min = t; nearestHit = shape.get(); } if(nearestHit) { auto inter = new Intersection(ray, t_min); nearestHit->populate_intersection(*inter); return std::unique_ptr<Intersection>(inter); } return nullptr; }
IShape* NodeFactory::CreateRect(const Size2F& rectSize, const Color4F& color) { ShapeQuadMesh* mesh = MeshFactory::Instance().CreateShapeQuadMesh(rectSize, color); RETURN_NULL_IF_NULL(mesh); IMaterial* material = MaterialFactory::Instance().CreateShape(MEDUSA_PREFIX(Shape)); IShape* sprite = new IShape(); sprite->Initialize(); sprite->SetSizeToContent(SizeToContent::Mesh); sprite->SetMesh(mesh); sprite->SetMaterial(material); sprite->SetSize(rectSize); return sprite; }
IShape* NodeFactory::CreateRectBorder(const Size2F& rectSize, const Color4F& color) { auto mesh = MeshFactory::Instance().CreateShapeQuadMesh(rectSize, color); RETURN_NULL_IF_NULL(mesh); auto material = MaterialFactory::Instance().CreateShape(MEDUSA_PREFIX(Shape_WireFrame)); material->SetDrawMode(GraphicsDrawMode::LineStrip); IShape* sprite = new IShape(); sprite->Initialize(); sprite->SetSizeToContent(SizeToContent::Mesh); sprite->SetMesh(mesh); sprite->SetMaterial(material); sprite->SetSize(rectSize); return sprite; }
virtual bool Intersects(const IShape& shape) const override { return shape.Intersects(*this); }
// ************************************************************ // FindSnapPoint // ************************************************************ VARIANT_BOOL CMapView::FindSnapPoint(double tolerance, double xScreen, double yScreen, double* xFound, double* yFound) { double maxDist = GetProjectedTolerance(xScreen, yScreen, tolerance); double x, y; this->PixelToProjection(xScreen, yScreen, x, y); long shapeIndex; long pointIndex; VARIANT_BOOL vb; double distance; double minDist = DBL_MAX; IShapefile* foundShapefile = NULL; long foundShapeIndex; long foundPointIndex; bool digitizing = EditorHelper::IsDigitizingCursor((tkCursorMode)m_cursorMode); tkLayerSelection behavior; _shapeEditor->get_SnapBehavior(&behavior); long currentHandle = -1; bool currentLayerOnly = behavior == lsActiveLayer && digitizing; if (currentLayerOnly) _shapeEditor->get_LayerHandle(¤tHandle); for (long i = 0; i < this->GetNumLayers(); i++) { long layerHandle = this->GetLayerHandle(i); if (currentLayerOnly && layerHandle != currentHandle) continue; Layer* l = GetLayer(layerHandle); if (!l || !l->wasRendered) continue; CComPtr<IShapefile> sf = NULL; sf.Attach(this->GetShapefile(layerHandle)); if (sf) { VARIANT_BOOL snappable; sf->get_Snappable(&snappable); if (snappable) { sf->GetClosestVertex(x, y, maxDist, &shapeIndex, &pointIndex, &distance, &vb); if (vb) { if (distance < minDist) { minDist = distance; foundShapefile = sf; foundPointIndex = pointIndex; foundShapeIndex = shapeIndex; } } } } } bool result = false; if (minDist != DBL_MAX && foundShapefile) { IShape* shape = NULL; foundShapefile->get_Shape(foundShapeIndex, &shape); if (shape) { shape->get_XY(foundPointIndex, xFound, yFound, &vb); shape->Release(); result = true; } } return result; }
void AreaVisitor::printArea( IShape const & shape ) const { std::cout << "Area of " << shape.getName() << " is " << _area << std::endl; }
Color trace (const Ray& ray, std::set<IShape*>& sceneShapes, std::set<Light*>& sceneLights, int depth) { Color pixelColor (0.3); float near; Color color; Vector3D normal; IShape *shape = calculateIntersect (ray, sceneShapes, &near, normal, color); if (shape) { pixelColor = color; Point intersectionPoint = ray.calculate (near); Vector3D n; Color c; pixelColor = Color (0.0f); //Calculate illumination on intersected pixel for (auto light : sceneLights) { Vector3D lightDirection = (light->position () - intersectionPoint); float lightLenght = lightDirection.normalize (); const Ray shadowRay (intersectionPoint + normal * bias, lightDirection, lightLenght); float near = INFINITY; IShape *s = calculateIntersect (shadowRay, sceneShapes, &near, n, c); if (!s) //There is no object between the intersected pixel and this light. { float diffuseCoefficient = shape->diffuse (); float specularCoefficient = shape->specular (); pixelColor += ambientColor (color); if (diffuseCoefficient > 0.0f) pixelColor += diffuseColor (lightDirection, light, normal, color, diffuseCoefficient); if (specularCoefficient > 0.0f) pixelColor += specularColor (lightDirection, normal, ray, light, specularCoefficient); } else //Intersected pixel is shadowed!!! { pixelColor = color * 0.1; break; } } //Calculate the reflected color if ((shape->reflection () > 0) && depth <= MAX_DEPTH) { Vector3D reflDir = ray.direction () - normal * 2 * ray.direction ().dot (normal); reflDir.normalize (); Ray reflectionRay (intersectionPoint + normal * bias, reflDir); Color reflectionColor = trace (reflectionRay, sceneShapes, sceneLights, depth + 1); pixelColor += reflectionColor * shape->reflection (); } } pixelColor.clamp (); return pixelColor; }
IEntity* CreateMissle(EntityPtr owner, Vector2d pos, float rot, IDrawer * d) { IShape* shape = d->CreateLine(pos, pos + Vector2d(cos(rot*PI/180), sin(rot * PI/180)) * MISSLE_LENGTH, 100, 50, 50, MISSLE_WIDTH); shape->SetOrigin(Vector2d(MISSLE_WIDTH/2, 0)); return new Missle(owner, shape); }