void object::test<36>() { PointPtr point = poly_->getCentroid(); ensure( point != nullptr ); ensure( !point->isEmpty() ); ensure_equals( point->getGeometryTypeId(), geos::geom::GEOS_POINT ); // FREE MEMORY factory_->destroyGeometry(point); }
void PointList::BoxCoordinites (kkint32& minRow, kkint32& minCol, kkint32& maxRow, kkint32& maxCol ) { minRow = minCol = 999999; maxRow = maxCol = -1; for (iterator x = begin (); x != end (); x++) { PointPtr p = *x; if (p->Row () < minRow) minRow = p->Row (); if (p->Row () > maxRow) maxRow = p->Row (); if (p->Col () < minCol) minCol = p->Col (); if (p->Col () > maxCol) maxCol = p->Col (); } }
/** * @brief KmlExport::createTimespanPlacemark Creates a timespan placemark, which allows the * trajectory to be played forward in time. The placemark also contains pertinent data about * the vehicle's state at that timespan * @param timestampPoint * @param lastPlacemarkTime * @param newPlacemarkTime * @return Returns the placemark containing the timespan */ PlacemarkPtr KmlExport::createTimespanPlacemark(const LLAVCoordinates ×tampPoint, quint32 lastPlacemarkTime, quint32 newPlacemarkTime) { // Create coordinates CoordinatesPtr coordinates = factory->CreateCoordinates(); coordinates->add_latlngalt(timestampPoint.latitude, timestampPoint.longitude, timestampPoint.altitude); // Create point, using previous coordinates PointPtr point = factory->CreatePoint(); point->set_extrude(true); // Extrude to ground point->set_altitudemode(kmldom::ALTITUDEMODE_ABSOLUTE); point->set_coordinates(coordinates); // Create the timespan TimeSpanPtr timeSpan = factory->CreateTimeSpan(); QDateTime startTime = QDateTime::currentDateTimeUtc().addMSecs(lastPlacemarkTime); // FIXME: Make it a function of the realtime preferably gotten from the GPS QDateTime endTime = QDateTime::currentDateTimeUtc().addMSecs(newPlacemarkTime); timeSpan->set_begin(startTime.toString(dateTimeFormat).toStdString()); timeSpan->set_end(endTime.toString(dateTimeFormat).toStdString()); // Create an icon style. This arrow icon will be rotated and colored to represent velocity AttitudeActual::DataFields attitudeActualData = attitudeActual->getData(); AirspeedActual::DataFields airspeedActualData = airspeedActual->getData(); IconStylePtr iconStyle = factory->CreateIconStyle(); iconStyle->set_color(mapVelocity2Color(airspeedActualData.CalibratedAirspeed)); iconStyle->set_heading(attitudeActualData.Yaw + 180); //Adding 180 degrees because the arrow art points down, i.e. south. // Create a line style. This defines the style for the "legs" connecting the points to the ground. LineStylePtr lineStyle = factory->CreateLineStyle(); lineStyle->set_color(mapVelocity2Color(timestampPoint.groundspeed)); // Link the style to the icon StylePtr style = factory->CreateStyle(); style->set_linestyle(lineStyle); style->set_iconstyle(iconStyle); // Generate the placemark with all above attributes PlacemarkPtr placemark = factory->CreatePlacemark(); placemark->set_geometry(point); placemark->set_timeprimitive(timeSpan); placemark->set_name(QString("%1").arg(timeStamp / 1000.0).toStdString()); placemark->set_visibility(true); // Set the placemark to use the custom rotated arrow style placemark->set_styleurl("#directiveArrowStyle"); placemark->set_styleselector(style); // Add a nice description to the placemark placemark->set_description(informationString.toStdString()); return placemark; }
Point PointList::CalculateCenterPoint () { kkint32 totalRow = 0; kkint32 totalCol = 0; for (iterator x = begin (); x != end (); x++) { PointPtr p = *x; totalRow += p->Row (); totalCol += p->Col (); } kkint32 centerRow = (kkint32)((double)totalRow / (double)size () + 0.5); kkint32 centerCol = (kkint32)((double)totalCol / (double)size () + 0.5); return Point (centerRow, centerCol); }
void ogr2extrude_rec ( int nExtrude, GeometryPtr poKmlGeometry ) { PointPtr poKmlPoint; LineStringPtr poKmlLineString; PolygonPtr poKmlPolygon; MultiGeometryPtr poKmlMultiGeometry; size_t nGeom; size_t i; switch ( poKmlGeometry->Type ( ) ) { case kmldom::Type_Point: poKmlPoint = AsPoint ( poKmlGeometry ); poKmlPoint->set_extrude ( nExtrude ); break; case kmldom::Type_LineString: poKmlLineString = AsLineString ( poKmlGeometry ); poKmlLineString->set_extrude ( nExtrude ); break; case kmldom::Type_LinearRing: break; case kmldom::Type_Polygon: poKmlPolygon = AsPolygon ( poKmlGeometry ); poKmlPolygon->set_extrude ( nExtrude ); break; case kmldom::Type_MultiGeometry: poKmlMultiGeometry = AsMultiGeometry ( poKmlGeometry ); nGeom = poKmlMultiGeometry->get_geometry_array_size ( ); for ( i = 0; i < nGeom; i++ ) { ogr2extrude_rec ( nExtrude, poKmlMultiGeometry-> get_geometry_array_at ( i ) ); } break; default: break; } }
Measurement& Measurement::operator=(const Measurement &rhs) { id=rhs.id; centroid=rhs.centroid; PointPtr p; for(uint i=0;i<rhs.points.size();i++) { p.reset(new Point); *p=*(rhs.points[i]); points.push_back(p); } return *this; }
KKStr PointList::ToDelStr (char del) const { if (QueueSize () < 1) return "[]"; KKStr result (QueueSize () * 10); int count = 0; PointList::const_iterator idx; for (idx = begin (); idx != end (); ++idx, ++count) { PointPtr p = *idx; if (count > 0) result << del; result << p->Row () << del << p->Col (); } return result; } /* ToDelStr */
bool CurveCreateTool::MouseDown( const MouseButtonInput& e ) { if ( m_Instance.ReferencesObject() && m_Scene->IsEditable() ) { Math::Vector3 position; PickPosition( e.GetPosition().x, e.GetPosition().y, position ); PointPtr point = new Core::Point( m_Scene, new Content::Point( position ) ); point->SetParent( m_Instance ); point->SetTransient( true ); m_Scene->AddObject( point ); m_Instance->Dirty(); m_Scene->Execute( true ); } return __super::MouseDown( e ); }
void Cluster::add(const PointPtr &p) { if (points != NULL) assert(p->getDims() == points->p->getDims()); //make sure dimensions match if (find(p) != NULL) { //make sure p is not already in cluster return; } size++; LNodePtr node = new LNode; // Dynamically allocate new node LNodePtr ptr = points; node->p = p; if (points == NULL) { //case: empty cluster points = node; node->next = nullptr; return; } if (*node->p < *points->p) { //case: new point is smallest point node->next = points; points = node; return; } LNodePtr last = nullptr; while ( *p > *ptr->p) { //put in lexographic order last = ptr; if (ptr->next == NULL) {//if end of list node->next = nullptr; last->next = node; return; } ptr = ptr->next; } while (*p == *ptr->p && p > ptr->p) { //if points are equal sort by memory address last = ptr; //for reasons of comparison if (ptr->next == NULL) { node->next = nullptr; last->next = node; return; } ptr = ptr->next; } node->next = ptr; if (last != nullptr) last->next = node; else points = node; }
float PointList::ComputeSegmentLens (float heightFactor, float widthFactor ) const { if (QueueSize () < 1) return 0.0f; float totalLen = 0.0f; const_iterator idx; idx = begin (); PointPtr lastPoint = *idx; ++idx; while (idx != end ()) { PointPtr nextPoint = *idx; ++idx; float deltaHeight = (float)(nextPoint->Row () - lastPoint->Row ()) * heightFactor; float deltaWidth = (float)(nextPoint->Col () - lastPoint->Col ()) * widthFactor; float segmentLen = sqrt (deltaHeight * deltaHeight + deltaWidth * deltaWidth); totalLen += segmentLen; lastPoint = nextPoint; } return totalLen; } /* ComputeSegmentLens */
void object::test<38>() { // First centroid PointPtr point = poly_->getCentroid(); ensure( point != nullptr ); ensure( !point->isEmpty() ); ensure_equals( point->getGeometryTypeId(), geos::geom::GEOS_POINT ); CoordinateCPtr pointCoord = point->getCoordinate(); ensure( pointCoord != nullptr ); geos::geom::Coordinate pointCentr(*pointCoord); // FREE MEMORY factory_->destroyGeometry(point); // Second centroid geos::geom::Coordinate coordCentr; bool isCentroid = poly_->getCentroid(coordCentr); ensure( isCentroid ); // Comparison of two centroids ensure_equals( "Check Polygon::getCentroid() functions.", coordCentr, pointCentr ); }
void CurveCreateTool::CreateInstance( const Math::Vector3& position ) { if (m_Instance.ReferencesObject()) { // remove temp reference m_Scene->RemoveObject( m_Instance ); } m_Instance = new Core::Curve( m_Scene, new Content::Curve() ); m_Instance->SetSelected( true ); m_Instance->SetTransient( true ); m_Instance->SetCurveType( s_CurveType ); m_Scene->AddObject( m_Instance ); PointPtr point = new Core::Point( m_Scene, new Content::Point( position ) ); point->SetParent( m_Instance ); point->SetTransient( true ); m_Scene->AddObject( point ); m_Instance->Evaluate( GraphDirections::Downstream ); }
void object::test<11>() { geos::geom::Coordinate coord(x_, y_, z_); geos::geom::CoordinateArraySequence sequence; sequence.add(coord); PointPtr pt = factory_.createPoint(sequence); ensure( "createPoint() returned null pointer.", pt != 0 ); ensure( "createPoint() returned empty point.", !pt->isEmpty() ); ensure( pt->isSimple() ); ensure( pt->isValid() ); ensure( pt->getCoordinate() != 0 ); CoordinateCPtr pcoord = pt->getCoordinate(); ensure( pcoord != 0 ); ensure_equals( pcoord->x, x_ ); ensure_equals( pcoord->y, y_ ); ensure_equals( pcoord->z, z_ ); GeometryPtr geo = 0; geo = pt->getEnvelope(); ensure( geo != 0 ); ensure( !geo->isEmpty() ); factory_.destroyGeometry(geo); geo = pt->getCentroid(); ensure( geo != 0 ); ensure( !geo->isEmpty() ); factory_.destroyGeometry(geo); geo = pt->getBoundary(); ensure( geo != 0 ); ensure( geo->isEmpty() ); factory_.destroyGeometry(geo); geo = pt->convexHull(); ensure( geo != 0 ); ensure( !geo->isEmpty() ); factory_.destroyGeometry(geo); ensure_equals( pt->getGeometryTypeId(), geos::geom::GEOS_POINT ); ensure_equals( pt->getDimension(), geos::geom::Dimension::P ); ensure_equals( pt->getBoundaryDimension(), geos::geom::Dimension::False ); ensure_equals( pt->getNumPoints(), 1u ); ensure_equals( pt->getLength(), 0.0 ); ensure_equals( pt->getArea(), 0.0 ); // FREE MEMORY factory_.destroyGeometry(pt); }
void object::test<8>() { PointPtr pt = factory_.createPoint(); ensure( "createPoint() returned null pointer.", pt != 0 ); ensure( "createPoint() returned non-empty point.", pt->isEmpty() ); ensure( pt->isSimple() ); ensure( pt->isValid() ); ensure( pt->getCentroid() == 0 ); ensure( pt->getCoordinate() == 0 ); GeometryPtr geo = 0; geo = pt->getEnvelope(); ensure( geo != 0 ); ensure( geo->isEmpty() ); factory_.destroyGeometry(geo); geo = pt->getBoundary(); ensure( geo != 0 ); ensure( geo->isEmpty() ); factory_.destroyGeometry(geo); geo = pt->convexHull(); ensure( geo != 0 ); ensure( geo->isEmpty() ); factory_.destroyGeometry(geo); ensure_equals( pt->getGeometryTypeId(), geos::geom::GEOS_POINT ); ensure_equals( pt->getDimension(), geos::geom::Dimension::P ); ensure_equals( pt->getBoundaryDimension(), geos::geom::Dimension::False ); ensure_equals( pt->getNumPoints(), 0u ); ensure_equals( pt->getLength(), 0.0 ); ensure_equals( pt->getArea(), 0.0 ); // FREE MEMORY factory_.destroyGeometry(pt); }
int kml2extrude_rec ( GeometryPtr poKmlGeometry, int *pnExtrude ) { PointPtr poKmlPoint; LineStringPtr poKmlLineString; PolygonPtr poKmlPolygon; MultiGeometryPtr poKmlMultiGeometry; size_t nGeom; size_t i; switch ( poKmlGeometry->Type ( ) ) { case kmldom::Type_Point: poKmlPoint = AsPoint ( poKmlGeometry ); if ( poKmlPoint->has_extrude ( ) ) { *pnExtrude = poKmlPoint->get_extrude ( ); return TRUE; } break; case kmldom::Type_LineString: poKmlLineString = AsLineString ( poKmlGeometry ); if ( poKmlLineString->has_extrude ( ) ) { *pnExtrude = poKmlLineString->get_extrude ( ); return TRUE; } break; case kmldom::Type_LinearRing: break; case kmldom::Type_Polygon: poKmlPolygon = AsPolygon ( poKmlGeometry ); if ( poKmlPolygon->has_extrude ( ) ) { *pnExtrude = poKmlPolygon->get_extrude ( ); return TRUE; } break; case kmldom::Type_MultiGeometry: poKmlMultiGeometry = AsMultiGeometry ( poKmlGeometry ); nGeom = poKmlMultiGeometry->get_geometry_array_size ( ); for ( i = 0; i < nGeom; i++ ) { if ( kml2extrude_rec ( poKmlMultiGeometry-> get_geometry_array_at ( i ), pnExtrude ) ) return TRUE; } break; default: break; } return FALSE; }
ElementPtr geom2kml ( OGRGeometry * poOgrGeom, int extra, KmlFactory * poKmlFactory ) { int i; if ( !poOgrGeom ) { return NULL; } /***** ogr geom vars *****/ OGRPoint *poOgrPoint = NULL; OGRLineString *poOgrLineString; OGRPolygon *poOgrPolygon; OGRGeometryCollection *poOgrMultiGeom; /***** libkml geom vars *****/ CoordinatesPtr coordinates; PointPtr poKmlPoint; LineStringPtr poKmlLineString; LinearRingPtr poKmlLinearRing; OuterBoundaryIsPtr poKmlOuterRing; InnerBoundaryIsPtr poKmlInnerRing; PolygonPtr poKmlPolygon; MultiGeometryPtr poKmlMultiGeometry; ElementPtr poKmlGeometry; ElementPtr poKmlTmpGeometry; /***** other vars *****/ double x, y, z; int numpoints = 0; int nGeom; OGRwkbGeometryType type = poOgrGeom->getGeometryType ( ); switch ( type ) { case wkbPoint: poOgrPoint = ( OGRPoint * ) poOgrGeom; if (poOgrPoint->getCoordinateDimension() == 0) { poKmlGeometry = poKmlPoint = poKmlFactory->CreatePoint ( ); } else { x = poOgrPoint->getX ( ); y = poOgrPoint->getY ( ); if ( x > 180 ) x -= 360; coordinates = poKmlFactory->CreateCoordinates ( ); coordinates->add_latlng ( y, x ); poKmlGeometry = poKmlPoint = poKmlFactory->CreatePoint ( ); poKmlPoint->set_coordinates ( coordinates ); } break; case wkbPoint25D: poOgrPoint = ( OGRPoint * ) poOgrGeom; x = poOgrPoint->getX ( ); y = poOgrPoint->getY ( ); z = poOgrPoint->getZ ( ); if ( x > 180 ) x -= 360; coordinates = poKmlFactory->CreateCoordinates ( ); coordinates->add_latlngalt ( y, x, z ); poKmlGeometry = poKmlPoint = poKmlFactory->CreatePoint ( ); poKmlPoint->set_coordinates ( coordinates ); break; case wkbLineString: poOgrLineString = ( OGRLineString * ) poOgrGeom; if( extra >= 0 ) { ((OGRLinearRing*)poOgrGeom)->closeRings(); } numpoints = poOgrLineString->getNumPoints ( ); if( extra >= 0 ) { if( numpoints < 4 && CPLTestBool(CPLGetConfigOption("LIBKML_STRICT_COMPLIANCE", "TRUE")) ) { CPLError(CE_Failure, CPLE_NotSupported, "A linearring should have at least 4 points"); return NULL; } } else { if( numpoints < 2 && CPLTestBool(CPLGetConfigOption("LIBKML_STRICT_COMPLIANCE", "TRUE")) ) { CPLError(CE_Failure, CPLE_NotSupported, "A linestring should have at least 2 points"); return NULL; } } coordinates = poKmlFactory->CreateCoordinates ( ); poOgrPoint = new OGRPoint ( ); for ( i = 0; i < numpoints; i++ ) { poOgrLineString->getPoint ( i, poOgrPoint ); x = poOgrPoint->getX ( ); y = poOgrPoint->getY ( ); if ( x > 180 ) x -= 360; coordinates->add_latlng ( y, x ); } delete poOgrPoint; /***** check if its a wkbLinearRing *****/ if ( extra < 0 ) { poKmlGeometry = poKmlLineString = poKmlFactory->CreateLineString ( ); poKmlLineString->set_coordinates ( coordinates ); break; } /***** fallthrough *****/ case wkbLinearRing: //this case is for readability only poKmlLinearRing = poKmlFactory->CreateLinearRing ( ); poKmlLinearRing->set_coordinates ( coordinates ); if ( !extra ) { poKmlOuterRing = poKmlFactory->CreateOuterBoundaryIs ( ); poKmlOuterRing->set_linearring ( poKmlLinearRing ); poKmlGeometry = poKmlOuterRing; } else { poKmlGeometry = poKmlInnerRing = poKmlFactory->CreateInnerBoundaryIs ( ); poKmlInnerRing->set_linearring ( poKmlLinearRing ); } break; case wkbLineString25D: poOgrLineString = ( OGRLineString * ) poOgrGeom; if( extra >= 0 ) { ((OGRLinearRing*)poOgrGeom)->closeRings(); } numpoints = poOgrLineString->getNumPoints ( ); if( extra >= 0 ) { if( numpoints < 4 && CPLTestBool(CPLGetConfigOption("LIBKML_STRICT_COMPLIANCE", "TRUE")) ) { CPLError(CE_Failure, CPLE_NotSupported, "A linearring should have at least 4 points"); return NULL; } } else { if( numpoints < 2 && CPLTestBool(CPLGetConfigOption("LIBKML_STRICT_COMPLIANCE", "TRUE")) ) { CPLError(CE_Failure, CPLE_NotSupported, "A linestring should have at least 2 points"); return NULL; } } coordinates = poKmlFactory->CreateCoordinates ( ); poOgrPoint = new OGRPoint ( ); for ( i = 0; i < numpoints; i++ ) { poOgrLineString->getPoint ( i, poOgrPoint ); x = poOgrPoint->getX ( ); y = poOgrPoint->getY ( ); z = poOgrPoint->getZ ( ); if ( x > 180 ) x -= 360; coordinates->add_latlngalt ( y, x, z ); } delete poOgrPoint; /***** check if its a wkbLinearRing *****/ if ( extra < 0 ) { poKmlGeometry = poKmlLineString = poKmlFactory->CreateLineString ( ); poKmlLineString->set_coordinates ( coordinates ); break; } /***** fallthrough *****/ //case wkbLinearRing25D: // this case is for readability only poKmlLinearRing = poKmlFactory->CreateLinearRing ( ); poKmlLinearRing->set_coordinates ( coordinates ); if ( !extra ) { poKmlGeometry = poKmlOuterRing = poKmlFactory->CreateOuterBoundaryIs ( ); poKmlOuterRing->set_linearring ( poKmlLinearRing ); } else { poKmlGeometry = poKmlInnerRing = poKmlFactory->CreateInnerBoundaryIs ( ); poKmlInnerRing->set_linearring ( poKmlLinearRing ); } break; case wkbPolygon: CPLErrorReset(); if( CPLTestBool(CPLGetConfigOption("LIBKML_STRICT_COMPLIANCE", "TRUE")) && OGRGeometryFactory::haveGEOS() && (!poOgrGeom->IsValid() || CPLGetLastErrorType() != CE_None) ) { CPLError(CE_Failure, CPLE_NotSupported, "Invalid polygon"); return NULL; } poOgrPolygon = ( OGRPolygon * ) poOgrGeom; poKmlGeometry = poKmlPolygon = poKmlFactory->CreatePolygon ( ); poKmlTmpGeometry = geom2kml ( poOgrPolygon->getExteriorRing ( ), 0, poKmlFactory ); poKmlPolygon-> set_outerboundaryis ( AsOuterBoundaryIs ( poKmlTmpGeometry ) ); nGeom = poOgrPolygon->getNumInteriorRings ( ); for ( i = 0; i < nGeom; i++ ) { poKmlTmpGeometry = geom2kml ( poOgrPolygon->getInteriorRing ( i ), i + 1, poKmlFactory ); poKmlPolygon-> add_innerboundaryis ( AsInnerBoundaryIs ( poKmlTmpGeometry ) ); } break; case wkbPolygon25D: CPLErrorReset(); if( CPLTestBool(CPLGetConfigOption("LIBKML_STRICT_COMPLIANCE", "TRUE")) && OGRGeometryFactory::haveGEOS() && (!poOgrGeom->IsValid() || CPLGetLastErrorType() != CE_None) ) { CPLError(CE_Failure, CPLE_NotSupported, "Invalid polygon"); return NULL; } poOgrPolygon = ( OGRPolygon * ) poOgrGeom; poKmlGeometry = poKmlPolygon = poKmlFactory->CreatePolygon ( ); poKmlTmpGeometry = geom2kml ( poOgrPolygon->getExteriorRing ( ), 0, poKmlFactory ); poKmlPolygon-> set_outerboundaryis ( AsOuterBoundaryIs ( poKmlTmpGeometry ) ); nGeom = poOgrPolygon->getNumInteriorRings ( ); for ( i = 0; i < nGeom; i++ ) { poKmlTmpGeometry = geom2kml ( poOgrPolygon->getInteriorRing ( i ), i + 1, poKmlFactory ); poKmlPolygon-> add_innerboundaryis ( AsInnerBoundaryIs ( poKmlTmpGeometry ) ); } break; case wkbMultiPoint: case wkbMultiLineString: case wkbMultiPolygon: case wkbGeometryCollection: case wkbMultiPoint25D: case wkbMultiLineString25D: case wkbMultiPolygon25D: case wkbGeometryCollection25D: poOgrMultiGeom = ( OGRGeometryCollection * ) poOgrGeom; nGeom = poOgrMultiGeom->getNumGeometries ( ); if( nGeom == 1 && CPLTestBool(CPLGetConfigOption("LIBKML_STRICT_COMPLIANCE", "TRUE")) ) { CPLDebug("LIBKML", "Turning multiple geometry into single geometry"); poKmlGeometry = geom2kml( poOgrMultiGeom->getGeometryRef ( 0 ), -1, poKmlFactory ); } else { if( nGeom == 0 && CPLTestBool(CPLGetConfigOption("LIBKML_STRICT_COMPLIANCE", "TRUE")) ) { CPLError(CE_Warning, CPLE_AppDefined, "Empty multi geometry are not recommended"); } poKmlGeometry = poKmlMultiGeometry = poKmlFactory->CreateMultiGeometry ( ); for ( i = 0; i < nGeom; i++ ) { poKmlTmpGeometry = geom2kml ( poOgrMultiGeom->getGeometryRef ( i ), -1, poKmlFactory ); poKmlMultiGeometry-> add_geometry ( AsGeometry ( poKmlTmpGeometry ) ); } } break; case wkbUnknown: case wkbNone: default: break; } return poKmlGeometry; }
static OGRGeometry *kml2geom_rec ( GeometryPtr poKmlGeometry, OGRSpatialReference *poOgrSRS) { /***** ogr geom vars *****/ OGRPoint *poOgrPoint; OGRLineString *poOgrLineString; OGRLinearRing *poOgrLinearRing; OGRPolygon *poOgrPolygon; OGRGeometryCollection *poOgrMultiGeometry; OGRGeometry *poOgrGeometry = NULL; OGRGeometry *poOgrTmpGeometry = NULL; /***** libkml geom vars *****/ CoordinatesPtr poKmlCoordinates; PointPtr poKmlPoint; LineStringPtr poKmlLineString; LinearRingPtr poKmlLinearRing; OuterBoundaryIsPtr poKmlOuterRing; InnerBoundaryIsPtr poKmlInnerRing; PolygonPtr poKmlPolygon; MultiGeometryPtr poKmlMultiGeometry; GxTrackPtr poKmlGxTrack; GxMultiTrackPtr poKmlGxMultiTrack; GeometryPtr poKmlTmpGeometry; Vec3 oKmlVec; size_t nRings, nCoords, nGeom, i; switch ( poKmlGeometry->Type ( ) ) { case kmldom::Type_Point: poKmlPoint = AsPoint ( poKmlGeometry ); if ( poKmlPoint->has_coordinates ( ) ) { poKmlCoordinates = poKmlPoint->get_coordinates ( ); nCoords = poKmlCoordinates->get_coordinates_array_size ( ); if (nCoords > 0) { oKmlVec = poKmlCoordinates->get_coordinates_array_at ( 0 ); if ( oKmlVec.has_altitude ( ) ) poOgrPoint = new OGRPoint ( oKmlVec.get_longitude ( ), oKmlVec.get_latitude ( ), oKmlVec.get_altitude ( ) ); else poOgrPoint = new OGRPoint ( oKmlVec.get_longitude ( ), oKmlVec.get_latitude ( ) ); poOgrGeometry = poOgrPoint; } else { poOgrGeometry = new OGRPoint(); } } else { poOgrGeometry = new OGRPoint(); } break; case kmldom::Type_LineString: poKmlLineString = AsLineString ( poKmlGeometry ); poOgrLineString = new OGRLineString ( ); if ( poKmlLineString->has_coordinates ( ) ) { poKmlCoordinates = poKmlLineString->get_coordinates ( ); nCoords = poKmlCoordinates->get_coordinates_array_size ( ); for ( i = 0; i < nCoords; i++ ) { oKmlVec = poKmlCoordinates->get_coordinates_array_at ( i ); if ( oKmlVec.has_altitude ( ) ) poOgrLineString-> addPoint ( oKmlVec.get_longitude ( ), oKmlVec.get_latitude ( ), oKmlVec.get_altitude ( ) ); else poOgrLineString-> addPoint ( oKmlVec.get_longitude ( ), oKmlVec.get_latitude ( ) ); } } poOgrGeometry = poOgrLineString; break; case kmldom::Type_LinearRing: poKmlLinearRing = AsLinearRing ( poKmlGeometry ); poOgrLinearRing = new OGRLinearRing ( ); if ( poKmlLinearRing->has_coordinates ( ) ) { poKmlCoordinates = poKmlLinearRing->get_coordinates ( ); nCoords = poKmlCoordinates->get_coordinates_array_size ( ); for ( i = 0; i < nCoords; i++ ) { oKmlVec = poKmlCoordinates->get_coordinates_array_at ( i ); if ( oKmlVec.has_altitude ( ) ) poOgrLinearRing-> addPoint ( oKmlVec.get_longitude ( ), oKmlVec.get_latitude ( ), oKmlVec.get_altitude ( ) ); else poOgrLinearRing-> addPoint ( oKmlVec.get_longitude ( ), oKmlVec.get_latitude ( ) ); } } poOgrGeometry = poOgrLinearRing; break; case kmldom::Type_Polygon: poKmlPolygon = AsPolygon ( poKmlGeometry ); poOgrPolygon = new OGRPolygon ( ); if ( poKmlPolygon->has_outerboundaryis ( ) ) { poKmlOuterRing = poKmlPolygon->get_outerboundaryis ( ); poKmlLinearRing = poKmlOuterRing->get_linearring ( ); if (poKmlLinearRing) { poOgrTmpGeometry = kml2geom_rec ( poKmlLinearRing, poOgrSRS ); poOgrPolygon-> addRingDirectly ( ( OGRLinearRing * ) poOgrTmpGeometry ); } } nRings = poKmlPolygon->get_innerboundaryis_array_size ( ); for ( i = 0; i < nRings; i++ ) { poKmlInnerRing = poKmlPolygon->get_innerboundaryis_array_at ( i ); poKmlLinearRing = poKmlInnerRing->get_linearring ( ); if (poKmlLinearRing) { poOgrTmpGeometry = kml2geom_rec ( poKmlLinearRing, poOgrSRS ); poOgrPolygon-> addRingDirectly ( ( OGRLinearRing * ) poOgrTmpGeometry ); } } poOgrGeometry = poOgrPolygon; break; case kmldom::Type_MultiGeometry: { poKmlMultiGeometry = AsMultiGeometry ( poKmlGeometry ); nGeom = poKmlMultiGeometry->get_geometry_array_size ( ); // Detect subgeometry type to instantiate appropriate // multi geometry type. kmldom::KmlDomType type = kmldom::Type_Unknown; for ( i = 0; i < nGeom; i++ ) { poKmlTmpGeometry = poKmlMultiGeometry->get_geometry_array_at ( i ); if (type == kmldom::Type_Unknown) type = poKmlTmpGeometry->Type(); else if (type != poKmlTmpGeometry->Type()) { type = kmldom::Type_Unknown; break; } } if (type == kmldom::Type_Point) poOgrMultiGeometry = new OGRMultiPoint(); else if (type == kmldom::Type_LineString) poOgrMultiGeometry = new OGRMultiLineString(); else if (type == kmldom::Type_Polygon) poOgrMultiGeometry = new OGRMultiPolygon(); else poOgrMultiGeometry = new OGRGeometryCollection (); for ( i = 0; i < nGeom; i++ ) { poKmlTmpGeometry = poKmlMultiGeometry->get_geometry_array_at ( i ); poOgrTmpGeometry = kml2geom_rec ( poKmlTmpGeometry, poOgrSRS ); poOgrMultiGeometry->addGeometryDirectly ( poOgrTmpGeometry ); } poOgrGeometry = poOgrMultiGeometry; break; } case kmldom::Type_GxTrack: poKmlGxTrack = AsGxTrack ( poKmlGeometry ); nCoords = poKmlGxTrack->get_gx_coord_array_size(); poOgrLineString = new OGRLineString ( ); for ( i = 0; i < nCoords; i++ ) { oKmlVec = poKmlGxTrack->get_gx_coord_array_at ( i ); if ( oKmlVec.has_altitude ( ) ) poOgrLineString-> addPoint ( oKmlVec.get_longitude ( ), oKmlVec.get_latitude ( ), oKmlVec.get_altitude ( ) ); else poOgrLineString-> addPoint ( oKmlVec.get_longitude ( ), oKmlVec.get_latitude ( ) ); } poOgrGeometry = poOgrLineString; break; case kmldom::Type_GxMultiTrack: { poKmlGxMultiTrack = AsGxMultiTrack ( poKmlGeometry ); nGeom = poKmlGxMultiTrack->get_gx_track_array_size ( ); poOgrMultiGeometry = new OGRMultiLineString(); for( size_t j = 0; j < nGeom; j++ ) { poKmlGxTrack = poKmlGxMultiTrack->get_gx_track_array_at ( j ); nCoords = poKmlGxTrack->get_gx_coord_array_size(); poOgrLineString = new OGRLineString ( ); for ( i = 0; i < nCoords; i++ ) { oKmlVec = poKmlGxTrack->get_gx_coord_array_at ( i ); if ( oKmlVec.has_altitude ( ) ) poOgrLineString-> addPoint ( oKmlVec.get_longitude ( ), oKmlVec.get_latitude ( ), oKmlVec.get_altitude ( ) ); else poOgrLineString-> addPoint ( oKmlVec.get_longitude ( ), oKmlVec.get_latitude ( ) ); } poOgrMultiGeometry->addGeometryDirectly(poOgrLineString); } poOgrGeometry = poOgrMultiGeometry; break; } default: break; } if (poOgrGeometry) poOgrGeometry->assignSpatialReference(poOgrSRS); return poOgrGeometry; }
void ogr2altitudemode_rec ( GeometryPtr poKmlGeometry, int iAltitudeMode, int isGX ) { PointPtr poKmlPoint; LineStringPtr poKmlLineString; PolygonPtr poKmlPolygon; MultiGeometryPtr poKmlMultiGeometry; size_t nGeom; size_t i; switch ( poKmlGeometry->Type ( ) ) { case kmldom::Type_Point: poKmlPoint = AsPoint ( poKmlGeometry ); if ( !isGX ) poKmlPoint->set_altitudemode ( iAltitudeMode ); else poKmlPoint->set_gx_altitudemode ( iAltitudeMode ); break; case kmldom::Type_LineString: poKmlLineString = AsLineString ( poKmlGeometry ); if ( !isGX ) poKmlLineString->set_altitudemode ( iAltitudeMode ); else poKmlLineString->set_gx_altitudemode ( iAltitudeMode ); break; case kmldom::Type_LinearRing: break; case kmldom::Type_Polygon: poKmlPolygon = AsPolygon ( poKmlGeometry ); if ( !isGX ) poKmlPolygon->set_altitudemode ( iAltitudeMode ); else poKmlPolygon->set_gx_altitudemode ( iAltitudeMode ); break; case kmldom::Type_MultiGeometry: poKmlMultiGeometry = AsMultiGeometry ( poKmlGeometry ); nGeom = poKmlMultiGeometry->get_geometry_array_size ( ); for ( i = 0; i < nGeom; i++ ) { ogr2altitudemode_rec ( poKmlMultiGeometry-> get_geometry_array_at ( i ), iAltitudeMode, isGX ); } break; default: break; } }
void frts::Drawer::updatePosition(const SharedManagerPtr& shared, PointPtr pos, Point::value zLevel, const RegionManagerPtr& regionManager, const ModelFactoryPtr& modelFactory, const GraphicDataPtr& graphicData, const ModelDataPtr& modelData) { // Pos is not a reference because we may override it. assert(shared != nullptr); assert(pos != nullptr); assert(initialized); // We only render on the same z-level or levels below. if (pos->getZ() > zLevel) { return; } // Change pos if it is below because we render always relative to the current zLevel. // Also we check if it is necessary to render (this may change later depending on transparency). bool renderPos = (pos->getZ() == zLevel); if (pos->getZ() < zLevel) { pos = modelFactory->makePoint(pos->getX(), pos->getY(), zLevel); } // The rectangle on the screen which should be rendered. auto mapArea = graphicData->getMapArea(); auto renderX = mapArea.x + regionToScreenX(pos->getX(), shared); auto renderY = mapArea.y + regionToScreenY(pos->getY(), shared); auto renderWidth = std::min(static_cast<GraphicData::pixel>(graphicData->getZoom() * graphicData->getTileWidth()), mapArea.x + mapArea.width - renderX); auto renderHeight = std::min(static_cast<GraphicData::pixel>(graphicData->getZoom() * graphicData->getTileHeight()), mapArea.y + mapArea.height - renderY); SDL_Rect rectToRender = { static_cast<int>(renderX), static_cast<int>(renderY), static_cast<int>(renderWidth), static_cast<int>(renderHeight) }; SDL_SetRenderDrawColor(renderer.get(), tileBackgroundR, tileBackgroundG, tileBackgroundB, 0); // Check if the position is in the map rectangle. if (!mapArea.isPixelInRect(renderX, renderY)) { return; } // Because of zoom it might be outside the region, so let's just render the background. if (pos->getX() >= modelData->getMapSizeX() || pos->getY() >= modelData->getMapSizeY()) { SDL_RenderFillRect(renderer.get(), &rectToRender); return; } // Get block. auto renderableId = shared->makeId(Sdl2Ids::renderable()); auto block = regionManager->getBlock(pos, shared); auto entities = block->getByComponent(renderableId); // Stacking support. IdUnorderedSet stacked; // Check for transparency. Currently we only render blocks below if the first entity (the assumed background) has it. auto filledBackground = false; if (entities.size() > 0) { auto transparency = getTransparency(entities, renderableId); if (transparency > 0) { SDL_RenderFillRect(renderer.get(), &rectToRender); filledBackground = true; // Even if the position on the current z-level doesn't need rendering we can look through // so it's still necessary to do that. renderPos = true; } // Check descending if the entities are transparent. std::vector<EntityVector> allEntitiesBelow; for (Point::value i = 1; i <= transparency; ++i) { auto posBelow = modelFactory->makePoint(pos->getX(), pos->getY(), pos->getZ() - i); auto blockBelow = regionManager->getBlock(posBelow, shared); auto entitiesBelow = blockBelow->getByComponent(renderableId); allEntitiesBelow.push_back(entitiesBelow); // Initialize with a value greater 0 to keep going if there are no entities. frts::Point::value transparencyBelow = 1; if (entitiesBelow.size() > 0) { transparencyBelow = getTransparency(entitiesBelow, renderableId); } if (transparencyBelow == 0) { // Doesn't make sense to go deeper if not transparent. break; } } // Render beginning from the lowest one. for (auto it = allEntitiesBelow.rbegin(); it != allEntitiesBelow.rend(); ++it) { renderEntities(*it, renderableId, rectToRender, stacked, shared, graphicData->getZoom()); } } if (renderPos) { if (!filledBackground) { SDL_RenderFillRect(renderer.get(), &rectToRender); } renderEntities(entities, renderableId, rectToRender, stacked, shared, graphicData->getZoom()); } }