// Load the line from a file void CDrawLine::Load(CStream& archive ) { m_point_a = ReadPoint(archive); m_point_b = ReadPoint(archive); switch (xtype) { case xDash: case xLine: // Premote this type m_use_default_style = FALSE; xtype = xLineEx2; break; case xLineEx: // Load the line thickness BYTE LineThickness; archive >> LineThickness; LineStyle l; l.Colour = cBLACK; l.Style = PS_SOLID; l.Thickness = LineThickness; m_use_default_style = FALSE; m_style = m_pDesign->GetOptions()->AddStyle(&l); m_style = m_pDesign->GetOptions()->GetNewStyleNumber(m_style); xtype = xLineEx2; break; case xLineEx2: m_use_default_style = FALSE; archive >> m_style; m_style = m_pDesign->GetOptions()->GetNewStyleNumber(m_style); break; default: m_use_default_style = TRUE; break; } }
// Load the rectange from a file void CDrawMetaFile::Load(CStream& archive ) { // Read in the location m_point_a = ReadPoint(archive); m_point_b = ReadPoint(archive); archive >> m_metafile; m_metafile = m_pDesign->GetOptions()->GetNewMetaFileNumber(m_metafile); }
// The old version of this load void CDrawSquare::OldLoad(CStream& archive, int tp ) { BYTE LineThickness = 1; m_point_a = ReadPoint(archive); m_point_b = ReadPoint(archive); if (tp == xSquareEx) { archive >> LineThickness; }
// Load the rectange from a file void CDrawSquare::OldLoad2(CStream& archive ) { m_point_a = ReadPoint(archive); m_point_b = ReadPoint(archive); archive >> Style; Style = m_pDesign->GetOptions()->GetNewStyleNumber(Style); Fill = fsNONE; }
inline int ReadDouble(double *x) { static char c, neg; while((c = readchar()) < '-') {if(c == EOF) return EOF;} if(c == '.') {*x = ReadPoint();return 0;} neg = (c == '-') ? -1 : 1; *x = (neg == 1) ? c-'0' : 0; while((c = readchar()) >= '0') *x = (*x)*10 + c-'0'; if(c == '.') *x += ReadPoint(); *x *= neg; return 0; }
// Load the rectange from a file void CDrawSquare::Load(CStream& archive ) { // Load the version number WORD version; archive >> version; m_point_a = ReadPoint(archive); m_point_b = ReadPoint(archive); archive >> Style; archive >> Fill; Style = m_pDesign->GetOptions()->GetNewStyleNumber(Style); Fill = m_pDesign->GetOptions()->GetNewFillStyleNumber(Fill); }
StereoRecorder::StereoRecorder(bool fromFile) { is_truncated = is_processed = false; if ( fromFile ) { stamped_offset = 0; Read(false); assertid("OUT2"); filename = ReadString(); float t = ReadFloat(); if ( Datatype::PeakId() == "anim" ) { animation = new Animated<gmtl::Point3f>(); } else { setLocation(ReadPoint()); animation = 0; } if ( Datatype::PeakId() == "anim" ) { right_ear_animation = new Animated<gmtl::Vec3f>(); } else { right_ear = ReadVec(); right_ear_animation = 0; } head_size = ReadFloat(); head_absorption = ReadVec(); for ( unsigned int i = 0; i < 3; ++ i ) { head_absorption[i] = std::max(0.0f,powf(1.0f-head_absorption[i],4)); } std::cout << this->toString(); } else { animation = 0; right_ear_animation = 0; filename = ""; } has_samples = save_processed = false; tracks.push_back(new RecorderTrack()); tracks.push_back(new RecorderTrack()); }
void CDrawPower::Load(CStream &archive) { m_point_a = ReadPoint(archive); archive >> which >> dir >> str; m_point_b = m_point_a; m_segment = 0; }
TripleBandSoundFile::TripleBandSoundFile() { Read(false); assertid("3SRC"); for ( int i = 0; i < 3; ++ i ) { std::string fn = ReadString(); WaveFile w(fn.c_str()); soundfiles[i] = new SoundFile(w.ToFloat(),w.GetSampleSize(),0,true); filename[i] = fn; } mesh = 0; animation = 0; if ( Datatype::PeakId() == "anim" ) { animation = new Animated<gmtl::Point3f>(); } else if ( Datatype::PeakId() == "mesh" ) { Datatype::prefix = " +- " + Datatype::prefix; mesh = new Mesh(); Datatype::prefix = Datatype::prefix.substr(4); } else { setLocation(ReadPoint()); } if ( Datatype::PeakId() == "flt4" ) { gain = Datatype::ReadFloat(); } else { gain = 1.0f; } if ( Datatype::PeakId() == "flt4" ) { offset = (unsigned int) (Datatype::ReadFloat() * 44100.0f); } else { offset = 0; } std::cout << this->toString(); std::cout << Datatype::stringblock; Datatype::stringblock = ""; }
void QgsMssqlGeometryParser::ReadMultiPoint( int iShape ) { int i, iCount; iCount = nNumShapes - iShape - 1; if ( iCount <= 0 ) return; // copy byte order CopyBytes( &chByteOrder, 1 ); // copy type int wkbType; if ( chProps & SP_HASZVALUES ) wkbType = QGis::WKBMultiPoint25D; else wkbType = QGis::WKBMultiPoint; CopyBytes( &wkbType, 4 ); // copy point count CopyBytes( &iCount, 4 ); // copy points for ( i = iShape + 1; i < nNumShapes; i++ ) { if ( ParentOffset( i ) == ( unsigned int )iShape ) { if ( ShapeType( i ) == ST_POINT ) ReadPoint( i ); } } }
void Ctrl::DoMouseButton(int event, CParser& p) { int button = p.ReadInt(); Point pt = ReadPoint(p); int64 tm = p.ReadInt64(); (button == 0 ? mouseLeft : button == 2 ? mouseRight : mouseMiddle) = event == DOWN; if(event == DOWN) { if(ignoremouseup) { KillRepeat(); ignoreclick = false; ignoremouseup = false; } if(ignoreclick) return; } if(event == UP) { if(ignoreclick) EndIgnore(); } if(event == DOWN) if(sDistMax(mouseDownPos, pt) < GUI_DragDistance() && tm - mouseDownTime < 800) { event = DOUBLE; mouseDownTime = 0; } else { mouseDownPos = pt; mouseDownTime = tm; } DoMouseFB(decode(button, 0, LEFT, 2, RIGHT, MIDDLE)|event, pt, 0, p); }
HpInterp* ReadInterp(HpBinaryReader* reader) { switch (ChrReadingVersion) { case 0x02: { HpSplineInterp* interp = new HpSplineInterp(); interp->P1 = ReadPoint(reader); interp->P2 = ReadPoint(reader); // interp->autorelease(); CC_AUTO_RELEASE(interp); return interp; } default: { float x1 = reader->ReadByte()*Byte2Double; float y1 = reader->ReadByte()*Byte2Double; float x2 = reader->ReadByte()*Byte2Double; float y2 = reader->ReadByte()*Byte2Double; return HpSplineInterp::interp(x1, y1, x2, y2); } } }
mapnik::geometry::multi_point<double> sqlserver_geometry_parser::ReadMultiPoint(int iShape) { mapnik::geometry::multi_point<double> geom; for (int i = iShape + 1; i < nNumShapes; i++) { if (ParentOffset(i) == (unsigned int)iShape) { if ( ShapeType(i) == ST_POINT ) { geom.emplace_back(ReadPoint(i)); } } } return geom; }
void CPainter::ReplaceColor(const CRGBColor& NewColor, const CRGBColor& OldColor) { for (int y = 0; y < m_pSurface->h; ++y) { for (int x = 0; x < m_pSurface->w; ++x) { CPoint point(x, y); if(ReadPoint(point) == OldColor) { DrawPoint(point, NewColor); } } } }
void CPainter::DrawPoint(const CPoint& Point, const CRGBColor& PointColor) { CPoint RealPoint = (m_pWindow != 0) ? Point + m_pWindow->GetClientRect().TopLeft() : Point; if (CRect(0, 0, m_pSurface->w, m_pSurface->h).HitTest(RealPoint) == CRect::RELPOS_INSIDE) { LockSurface(); Uint8* PixelOffset = static_cast<Uint8*>(m_pSurface->pixels) + m_pSurface->format->BytesPerPixel * RealPoint.XPos() + m_pSurface->pitch * RealPoint.YPos(); switch (m_pSurface->format->BytesPerPixel) { case 1: // 8 bpp *reinterpret_cast<Uint8*>(PixelOffset) = static_cast<Uint8>(MixColor(ReadPoint(Point), PointColor).SDLColor(m_pSurface->format)); break; case 2: // 16 bpp *reinterpret_cast<Uint16*>(PixelOffset) = static_cast<Uint16>(MixColor(ReadPoint(Point), PointColor).SDLColor(m_pSurface->format)); break; case 3: // 24 bpp { Uint32 PixelColor = MixColor(ReadPoint(Point), PointColor).SDLColor(m_pSurface->format); Uint8* pPixelSource = reinterpret_cast<Uint8*>(&PixelColor); Uint8* pPixelDest = reinterpret_cast<Uint8*>(PixelOffset); *pPixelDest = *pPixelSource; *(++pPixelDest) = *(++pPixelSource); *(++pPixelDest) = *(++pPixelSource); break; } case 4: // 32 bpp *reinterpret_cast<Uint32*>(PixelOffset) = static_cast<Uint32>(MixColor(ReadPoint(Point), PointColor).SDLColor(m_pSurface->format)); break; default: throw(Wg_Ex_SDL("CPainter::DrawPoint : Unrecognized BytesPerPixel.")); break; } UnlockSurface(); } }
void QgsMssqlGeometryParser::ReadGeometryCollection( int iShape ) { int i; int iCount = nNumShapes - iShape - 1;; if ( iCount <= 0 ) return; // copy byte order CopyBytes( &chByteOrder, 1 ); // copy type int wkbType = QGis::WKBUnknown;; CopyBytes( &wkbType, 4 ); // copy geom count CopyBytes( &iCount, 4 ); for ( i = iShape + 1; i < nNumShapes; i++ ) { if ( ParentOffset( i ) == ( unsigned int )iShape ) { switch ( ShapeType( i ) ) { case ST_POINT: ReadPoint( i ); break; case ST_LINESTRING: ReadLineString( i ); break; case ST_POLYGON: ReadPolygon( i ); break; case ST_MULTIPOINT: ReadMultiPoint( i ); break; case ST_MULTILINESTRING: ReadMultiLineString( i ); break; case ST_MULTIPOLYGON: ReadMultiPolygon( i ); break; case ST_GEOMETRYCOLLECTION: ReadGeometryCollection( i ); break; } } } }
OGRGeometryCollection* OGRMSSQLGeometryParser::ReadGeometryCollection(int iShape) { int i; OGRGeometryCollection* poGeomColl = new OGRGeometryCollection(); OGRGeometry* poGeom; for (i = iShape + 1; i < nNumShapes; i++) { poGeom = NULL; if (ParentOffset(i) == (unsigned int)iShape) { switch (ShapeType(i)) { case ST_POINT: poGeom = ReadPoint(i); break; case ST_LINESTRING: poGeom = ReadLineString(i); break; case ST_POLYGON: poGeom = ReadPolygon(i); break; case ST_MULTIPOINT: poGeom = ReadMultiPoint(i); break; case ST_MULTILINESTRING: poGeom = ReadMultiLineString(i); break; case ST_MULTIPOLYGON: poGeom = ReadMultiPolygon(i); break; case ST_GEOMETRYCOLLECTION: poGeom = ReadGeometryCollection(i); break; } } if ( poGeom ) poGeomColl->addGeometryDirectly( poGeom ); } return poGeomColl; }
OGRMultiPoint* OGRMSSQLGeometryParser::ReadMultiPoint(int iShape) { int i; OGRMultiPoint* poMultiPoint = new OGRMultiPoint(); OGRGeometry* poGeom; for (i = iShape + 1; i < nNumShapes; i++) { poGeom = NULL; if (ParentOffset(i) == (unsigned int)iShape) { if ( ShapeType(i) == ST_POINT ) poGeom = ReadPoint(i); } if ( poGeom ) poMultiPoint->addGeometryDirectly( poGeom ); } return poMultiPoint; }
SoundFile::SoundFile() { Read(false); assertid("SSRC"); filename = ReadString(); WaveFile w(filename.c_str()); data = w.ToFloat(); sample_owner = true; sample_length = w.GetSampleSize(); if ( !data || !sample_length ) { throw DatatypeException("Failed to open sound file " + filename); } soundfiles[0] = soundfiles[1] = soundfiles[2] = 0; data_low = data_mid = data_high = 0; mesh = 0; animation = 0; if ( Datatype::PeakId() == "anim" ) { animation = new Animated<gmtl::Point3f>(); } else if ( Datatype::PeakId() == "mesh" ) { Datatype::prefix = " +- " + Datatype::prefix; mesh = new Mesh(); Datatype::prefix = Datatype::prefix.substr(4); } else { setLocation(ReadPoint()); } if ( Datatype::PeakId() == "flt4" ) { gain = Datatype::ReadFloat(); } else { gain = 1.0f; } if ( Datatype::PeakId() == "flt4" ) { offset = (unsigned int) (Datatype::ReadFloat() * 44100.0f); } else { offset = 0; } std::cout << this->toString(); std::cout << Datatype::stringblock; Datatype::stringblock = ""; }
mapnik::geometry::geometry_collection<double> sqlserver_geometry_parser::ReadGeometryCollection(int iShape) { mapnik::geometry::geometry_collection<double> geom; for (int i = iShape + 1; i < nNumShapes; i++) { mapnik::geometry::geometry<double> shape = mapnik::geometry::geometry_empty(); if (ParentOffset(i) == (unsigned int)iShape) { switch (ShapeType(i)) { case ST_POINT: shape = ReadPoint(i); break; case ST_LINESTRING: shape = ReadLineString(i); break; case ST_POLYGON: shape = ReadPolygon(i); break; case ST_MULTIPOINT: shape = ReadMultiPoint(i); break; case ST_MULTILINESTRING: shape = ReadMultiLineString(i); break; case ST_MULTIPOLYGON: shape = ReadMultiPolygon(i); break; case ST_GEOMETRYCOLLECTION: shape = ReadGeometryCollection(i); break; } } geom.push_back(shape); } return geom; }
bool IgcReplay::Update() { if (!Enabled) return false; if (!update_time()) return true; // if need a new point while (cli.NeedData(t_simulation) && Enabled) { fixed t1 = fixed_zero; fixed Lat1, Lon1, Alt1, PAlt1; Enabled = ReadPoint(t1, Lat1, Lon1, Alt1, PAlt1); if (Enabled && positive(t1)) cli.Update(t1, Lon1, Lat1, Alt1, PAlt1); } if (t_simulation == fixed_zero) t_simulation = cli.GetMaxTime(); if (!Enabled) { Stop(); } else { fixed Alt, PAlt; GeoPoint Pos; cli.Interpolate(t_simulation, Pos, Alt, PAlt); const GeoVector v = cli.GetVector(t_simulation); on_advance(Pos, v.Distance, v.Bearing, Alt, PAlt, t_simulation); } return Enabled; }
mapnik::geometry::geometry<double> sqlserver_geometry_parser::parse(unsigned char* pszInput, int nLen) { if (nLen < 10) { throw sqlserver_geometry_parser_exception("not enough data, nLen < 10"); } pszData = pszInput; /* store the SRS id for further use */ nSRSId = ReadInt32(0); if ( ReadByte(4) != 1 ) { throw sqlserver_geometry_parser_exception("corrupt data, ReadByte(4) != 1"); } chProps = ReadByte(5); if ( chProps & SP_HASMVALUES ) nPointSize = 32; else if ( chProps & SP_HASZVALUES ) nPointSize = 24; else nPointSize = 16; mapnik::geometry::geometry<double> geom; if ( chProps & SP_ISSINGLEPOINT ) { // single point geometry nNumPoints = 1; nPointPos = 6; if (nLen < 6 + nPointSize) { throw sqlserver_geometry_parser_exception("not enough data, nLen < 6 + nPointSize"); } mapnik::geometry::point<double> point; if (colType == Geography) { point.x = ReadY(0); point.y = ReadX(0); } else { point.x = ReadX(0); point.y = ReadY(0); } geom = point; } else if ( chProps & SP_ISSINGLELINESEGMENT ) { // single line segment with 2 points nNumPoints = 2; nPointPos = 6; if (nLen < 6 + 2 * nPointSize) { throw sqlserver_geometry_parser_exception("not enough data, nLen < 6 + 2 * nPointSize"); } mapnik::geometry::line_string<double> line; if (colType == Geography) { line.emplace_back(ReadY(0), ReadX(0)); line.emplace_back(ReadY(1), ReadX(1)); } else { line.emplace_back(ReadX(0), ReadY(0)); line.emplace_back(ReadX(1), ReadY(1)); } geom = line; } else { // complex geometries nNumPoints = ReadInt32(6); if ( nNumPoints <= 0 ) { throw sqlserver_geometry_parser_exception("negative number of points, nNumPoints <= 0"); } // position of the point array nPointPos = 10; // position of the figures nFigurePos = nPointPos + nPointSize * nNumPoints + 4; if (nLen < nFigurePos) { throw sqlserver_geometry_parser_exception("not enough data, nLen < nFigurePos"); } nNumFigures = ReadInt32(nFigurePos - 4); if ( nNumFigures <= 0 ) { throw sqlserver_geometry_parser_exception("negative number of figures, nNumFigures <= 0"); } // position of the shapes nShapePos = nFigurePos + 5 * nNumFigures + 4; if (nLen < nShapePos) { throw sqlserver_geometry_parser_exception("not enough data, nLen < nShapePos"); } nNumShapes = ReadInt32(nShapePos - 4); if (nLen < nShapePos + 9 * nNumShapes) { throw sqlserver_geometry_parser_exception("not enough data, nLen < nShapePos + 9 * nNumShapes"); } if ( nNumShapes <= 0 ) { throw sqlserver_geometry_parser_exception("negative number of shapes, nNumShapes <= 0"); } // pick up the root shape if ( ParentOffset(0) != 0xFFFFFFFF) { throw sqlserver_geometry_parser_exception("corrupt data, ParentOffset(0) != 0xFFFFFFFF"); } // determine the shape type switch (ShapeType(0)) { case ST_POINT: geom = ReadPoint(0); break; case ST_LINESTRING: geom = ReadLineString(0); break; case ST_POLYGON: geom = ReadPolygon(0); break; case ST_MULTIPOINT: geom = ReadMultiPoint(0); break; case ST_MULTILINESTRING: geom = ReadMultiLineString(0); break; case ST_MULTIPOLYGON: geom = ReadMultiPolygon(0); break; case ST_GEOMETRYCOLLECTION: geom = ReadGeometryCollection(0); break; default: throw sqlserver_geometry_parser_exception("unsupported geometry type"); } } return geom; }
OGRErr OGRMSSQLGeometryParser::ParseSqlGeometry(unsigned char* pszInput, int nLen, OGRGeometry **poGeom) { if (nLen < 10) return OGRERR_NOT_ENOUGH_DATA; pszData = pszInput; /* store the SRS id for further use */ nSRSId = ReadInt32(0); if ( ReadByte(4) != 1 ) { return OGRERR_CORRUPT_DATA; } chProps = ReadByte(5); if ( chProps & SP_HASMVALUES ) nPointSize = 32; else if ( chProps & SP_HASZVALUES ) nPointSize = 24; else nPointSize = 16; if ( chProps & SP_ISSINGLEPOINT ) { // single point geometry nNumPoints = 1; nPointPos = 6; if (nLen < 6 + nPointSize) { return OGRERR_NOT_ENOUGH_DATA; } if (nColType == MSSQLCOLTYPE_GEOGRAPHY) { if (chProps & SP_HASZVALUES) *poGeom = new OGRPoint(ReadY(0), ReadX(0), ReadZ(0)); else *poGeom = new OGRPoint(ReadY(0), ReadX(0)); } else { if (chProps & SP_HASZVALUES) *poGeom = new OGRPoint(ReadX(0), ReadY(0), ReadZ(0)); else *poGeom = new OGRPoint(ReadX(0), ReadY(0)); } } else if ( chProps & SP_ISSINGLELINESEGMENT ) { // single line segment with 2 points nNumPoints = 2; nPointPos = 6; if (nLen < 6 + 2 * nPointSize) { return OGRERR_NOT_ENOUGH_DATA; } OGRLineString* line = new OGRLineString(); line->setNumPoints(2); if (nColType == MSSQLCOLTYPE_GEOGRAPHY) { if ( chProps & SP_HASZVALUES ) { line->setPoint(0, ReadY(0), ReadX(0), ReadZ(0)); line->setPoint(1, ReadY(1), ReadX(1), ReadZ(1)); } else { line->setPoint(0, ReadY(0), ReadX(0)); line->setPoint(1, ReadY(1), ReadX(1)); } } else { if ( chProps & SP_HASZVALUES ) { line->setPoint(0, ReadX(0), ReadY(0), ReadZ(0)); line->setPoint(1, ReadX(1), ReadY(1), ReadZ(1)); } else { line->setPoint(0, ReadX(0), ReadY(0)); line->setPoint(1, ReadX(1), ReadY(1)); } } *poGeom = line; } else { // complex geometries nNumPoints = ReadInt32(6); if ( nNumPoints <= 0 ) { return OGRERR_NONE; } // position of the point array nPointPos = 10; // position of the figures nFigurePos = nPointPos + nPointSize * nNumPoints + 4; if (nLen < nFigurePos) { return OGRERR_NOT_ENOUGH_DATA; } nNumFigures = ReadInt32(nFigurePos - 4); if ( nNumFigures <= 0 ) { return OGRERR_NONE; } // position of the shapes nShapePos = nFigurePos + 5 * nNumFigures + 4; if (nLen < nShapePos) { return OGRERR_NOT_ENOUGH_DATA; } nNumShapes = ReadInt32(nShapePos - 4); if (nLen < nShapePos + 9 * nNumShapes) { return OGRERR_NOT_ENOUGH_DATA; } if ( nNumShapes <= 0 ) { return OGRERR_NONE; } // pick up the root shape if ( ParentOffset(0) != 0xFFFFFFFF) { return OGRERR_CORRUPT_DATA; } // determine the shape type switch (ShapeType(0)) { case ST_POINT: *poGeom = ReadPoint(0); break; case ST_LINESTRING: *poGeom = ReadLineString(0); break; case ST_POLYGON: *poGeom = ReadPolygon(0); break; case ST_MULTIPOINT: *poGeom = ReadMultiPoint(0); break; case ST_MULTILINESTRING: *poGeom = ReadMultiLineString(0); break; case ST_MULTIPOLYGON: *poGeom = ReadMultiPolygon(0); break; case ST_GEOMETRYCOLLECTION: *poGeom = ReadGeometryCollection(0); break; default: return OGRERR_UNSUPPORTED_GEOMETRY_TYPE; } } return OGRERR_NONE; }
Painter& Painter::Path(CParser& p) { Pointf current(0, 0); while(!p.IsEof()) { int c = p.GetChar(); p.Spaces(); bool rel = IsLower(c); Pointf t, t1, t2; switch(ToUpper(c)) { case 'M': current = ReadPoint(p, current, rel); Move(current); case 'L': while(p.IsDouble2()) { current = ReadPoint(p, current, rel); Line(current); } break; case 'Z': Close(); break; case 'H': while(p.IsDouble2()) { current.x = p.ReadDouble() + rel * current.x; Line(current); } break; case 'V': while(p.IsDouble2()) { current.y = p.ReadDouble() + rel * current.y; Line(current); } break; case 'C': while(p.IsDouble2()) { t1 = ReadPoint(p, current, rel); t2 = ReadPoint(p, current, rel); current = ReadPoint(p, current, rel); Cubic(t1, t2, current); } break; case 'S': while(p.IsDouble2()) { t2 = ReadPoint(p, current, rel); current = ReadPoint(p, current, rel); Cubic(t2, current); } break; case 'Q': while(p.IsDouble2()) { t1 = ReadPoint(p, current, rel); current = ReadPoint(p, current, rel); Quadratic(t1, current); } break; case 'T': while(p.IsDouble2()) { current = ReadPoint(p, current, rel); Quadratic(current); } break; case 'A': while(p.IsDouble2()) { t1 = ReadPoint(p, Pointf(0, 0), false); double xangle = ReadDouble(p); bool large = ReadBool(p); bool sweep = ReadBool(p); current = ReadPoint(p, current, rel); SvgArc(t1, xangle * M_PI / 180.0, large, sweep, current); } break; default: return *this; } } return *this; }
BOOL CDataIndex::CreateIndex(LPCTSTR DataFileName, int Format, int Width, int Height, int NumberOfPoints, double MinX, double MaxX, double MinY, double MaxY, double MinZ, double MaxZ, BOOL Optimize) { if (m_HaveStarts) { delete [] m_CellStarts; m_HaveStarts = FALSE; } // create index for the given data file m_DataFileName = _T(DataFileName); // build index filename CFileSpec fs(DataFileName); fs.SetExt(".ldx"); // populate header values strcpy(m_Header.Signature, "LDAindex"); m_Header.Version = 1.1f; m_Header.Checksum = ComputeChecksum(DataFileName); m_Header.Format = Format; m_Header.MinX = 9999999999.0; m_Header.MinY = 9999999999.0; m_Header.MinZ = 9999999999.0; m_Header.MaxX = -9999999999.0; m_Header.MaxY = -9999999999.0; m_Header.MaxZ = -9999999999.0; m_Header.GridCellsAcross = Width; m_Header.GridCellsUp = Height; m_Header.TotalPointsIndexed = 0; // open data file CLidarData dat(DataFileName); LIDARRETURN pt; if (dat.IsValid()) { // create index file and write header m_FileHandle = fopen(fs.GetFullSpec(), "wb+"); if (m_FileHandle) { if (WriteHeader()) { if (MinX + MaxX + MinY + MaxY + MinZ + MaxZ == 0.0) { // scan data file for min/max values while (dat.ReadNextRecord(&pt)) { m_Header.MinX = std::min(m_Header.MinX, pt.X); m_Header.MinY = std::min(m_Header.MinY, pt.Y); m_Header.MinZ = std::min(m_Header.MinZ, double(pt.Elevation)); m_Header.MaxX = std::max(m_Header.MaxX, pt.X); m_Header.MaxY = std::max(m_Header.MaxY, pt.Y); m_Header.MaxZ = std::max(m_Header.MaxZ, double(pt.Elevation)); m_Header.TotalPointsIndexed ++; } dat.Rewind(); } else { // use values passed in m_Header.MinX = MinX; m_Header.MinY = MinY; m_Header.MinZ = MinZ; m_Header.MaxX = MaxX; m_Header.MaxY = MaxY; m_Header.MaxZ = MaxZ; m_Header.TotalPointsIndexed = NumberOfPoints; } // add 0.1 to max values to make sure we have a range that works for cell calculation // removed addition of 0.1 to header max values 3/21/2006 // m_Header.MaxX += 0.1; // m_Header.MaxY += 0.1; // m_Header.MaxZ += 0.1; // modified cell size calculation to add 0.1 to max data values 3/21/2006 double cellw = ((m_Header.MaxX + 0.1) - m_Header.MinX) / (double) m_Header.GridCellsAcross; double cellh = ((m_Header.MaxY + 0.1) - m_Header.MinY) / (double) m_Header.GridCellsUp; // read data file lines and build index int ptnum = 0; long offset = dat.GetPosition(); while (dat.ReadNextRecord(&pt)) { ptnum ++; m_Point.Offset = offset; m_Point.Column = (unsigned char) ((pt.X - m_Header.MinX) / cellw); m_Point.Row = (unsigned char) ((pt.Y - m_Header.MinY) / cellh); // m_Point.PointNumber = ptnum; WritePoint(); offset = dat.GetPosition(); } // rewrite the header to get min/max values and number of points WriteHeader(); // improve the index if (m_Header.TotalPointsIndexed && Optimize) { // allocate space for entire index INDEXENTRY* list = new INDEXENTRY[m_Header.TotalPointsIndexed]; if (list) { // rewind to start of index entries fseek(m_FileHandle, 128, SEEK_SET); for (int i = 0; i < m_Header.TotalPointsIndexed; i ++) { ReadPoint(); list[i].Column = m_Point.Column; list[i].Row = m_Point.Row; list[i].Offset = m_Point.Offset; } // sort list qsort(list, m_Header.TotalPointsIndexed, sizeof(INDEXENTRY), CompareIndexEntries); // re-write // rewind to start of index entries fseek(m_FileHandle, 128, SEEK_SET); for (int i = 0; i < m_Header.TotalPointsIndexed; i ++) { m_Point.Column = list[i].Column; m_Point.Row = list[i].Row; m_Point.Offset = list[i].Offset; WritePoint(); } // create cell starting point file int colrow; m_CellStarts = new long[m_Header.GridCellsAcross * m_Header.GridCellsUp]; if (m_CellStarts) { // initialize starting points for (int i = 0; i < m_Header.GridCellsAcross * m_Header.GridCellsUp; i ++) m_CellStarts[i] = -1; for (int i = 0; i < m_Header.TotalPointsIndexed; i ++) { colrow = list[i].Column * m_Header.GridCellsUp + list[i].Row; if (m_CellStarts[colrow] < 0) m_CellStarts[colrow] = i; } // write file CFileSpec ifs(fs.GetFullSpec()); ifs.SetExt(".ldi"); FILE* f = fopen(ifs.GetFullSpec(), "wb"); if (f) { // use same header as index with slightly different signature strcpy(m_Header.Signature, "LDAstarts"); fwrite(&m_Header, sizeof(header), 1, f); // seek to end of header area fseek(f, 128, SEEK_SET); // write starting points fwrite(m_CellStarts, sizeof(long), m_Header.GridCellsAcross * m_Header.GridCellsUp, f); fclose(f); // reset header to correct signature strcpy(m_Header.Signature, "LDAindex"); } m_HaveStarts = TRUE; } delete [] list; } } fclose(m_FileHandle); // reopen in read mode and go to start of points m_FileHandle = fopen(fs.GetFullSpec(), "rb"); fseek(m_FileHandle, 128, SEEK_SET); m_Valid = TRUE; } } dat.Close(); } else { m_Valid = FALSE; } return(m_Valid); }
long CDataIndex::JumpToNextPointInRange(double minx, double miny, double maxx, double maxy, FILE* datafile) { int i, j; BOOL GoodJump; if (!m_HaveDataRange) { m_Range_MinX = minx; m_Range_MinY = miny; m_Range_MaxX = maxx; m_Range_MaxY = maxy; // do test to see if area of interest is within data set extents if (maxx < m_Header.MinX || minx > m_Header.MaxX || maxy < m_Header.MinY || miny > m_Header.MaxY) return(-1); // compute range of valid cells // modified cell size calculation to add 0.1 to max data values 3/21/2006 double cellw = ((m_Header.MaxX + 0.1) - m_Header.MinX) / (double) m_Header.GridCellsAcross; double cellh = ((m_Header.MaxY + 0.1) - m_Header.MinY) / (double) m_Header.GridCellsUp; m_Range_MinCellColumn = (unsigned char) (std::max(0.0, (minx - m_Header.MinX) / cellw)); m_Range_MaxCellColumn = (unsigned char) (std::min((double) m_Header.GridCellsAcross - 1.0, (maxx - m_Header.MinX) / cellw)); m_Range_MinCellRow = (unsigned char) (std::max(0.0, (miny - m_Header.MinY) / cellh)); m_Range_MaxCellRow = (unsigned char) (std::min((double) m_Header.GridCellsUp - 1.0, (maxy - m_Header.MinY) / cellh)); m_HaveDataRange = TRUE; // if using starts...jump to first point in LL cell GoodJump = FALSE; if (m_HaveStarts) { for (i = m_Range_MinCellColumn; i <= m_Range_MaxCellColumn; i ++) { for (j = m_Range_MinCellRow; j <= m_Range_MaxCellRow; j ++) { if (m_CellStarts[i * m_Header.GridCellsUp + j] >= 0) { fseek(m_FileHandle, 128 + m_CellStarts[i * m_Header.GridCellsUp + j] * sizeof(pt), SEEK_SET); GoodJump = TRUE; break; } } if (GoodJump) break; } if (!GoodJump) return(-1); } } while (ReadPoint()) { if (m_Point.Column >= m_Range_MinCellColumn && m_Point.Column <= m_Range_MaxCellColumn) { if (m_Point.Row >= m_Range_MinCellRow && m_Point.Row <= m_Range_MaxCellRow) { if (datafile) fseek(datafile, m_Point.Offset, SEEK_SET); return(m_Point.Offset); } else if (m_HaveStarts) { // if using starts, and point is in rows above search area, try to jump to point in next column and bottom cell of search area if (m_Point.Row > m_Range_MaxCellRow) { for (i = m_Point.Column + 1; i <= m_Range_MaxCellColumn; i ++) { for (j = m_Range_MinCellRow; j <= m_Range_MaxCellRow; j ++) { if (m_CellStarts[i * m_Header.GridCellsUp + j] >= 0) { fseek(m_FileHandle, 128 + m_CellStarts[i * m_Header.GridCellsUp + j] * sizeof(pt), SEEK_SET); GoodJump = TRUE; break; } } if (GoodJump) break; } if (!GoodJump) break; } } } else if (m_HaveStarts) { // since index is sorted on columns then rows, we must be outside the search area break; } } m_HaveDataRange = FALSE; return(-1); }
/** * This tutorial demonstrates simple sending of messages over the ROS system. */ int main(int argc, char **argv) { /** * The ros::init() function needs to see argc and argv so that it can perform * any ROS arguments and name remapping that were provided at the command line. For programmatic * remappings you can use a different version of init() which takes remappings * directly, but for most command-line programs, passing argc and argv is the easiest * way to do it. The third argument to init() is the name of the node. * * You must call one of the versions of ros::init() before using any other * part of the ROS system. */ ros::init(argc, argv, "talker"); /** * NodeHandle is the main access point to communications with the ROS system. * The first NodeHandle constructed will fully initialize this node, and the last * NodeHandle destructed will close down the node. */ ros::NodeHandle n; /** * The advertise() function is how you tell ROS that you want to * publish on a given topic name. This invokes a call to the ROS * master node, which keeps a registry of who is publishing and who * is subscribing. After this advertise() call is made, the master * node will notify anyone who is trying to subscribe to this topic name, * and they will in turn negotiate a peer-to-peer connection with this * node. advertise() returns a Publisher object which allows you to * publish messages on that topic through a call to publish(). Once * all copies of the returned Publisher object are destroyed, the topic * will be automatically unadvertised. * * The second parameter to advertise() is the size of the message queue * used for publishing messages. If messages are published more quickly * than we can send them, the number here specifies how many messages to * buffer up before throwing some away. */ ros::Publisher pose2D_pub = n.advertise<geometry_msgs::Pose2D>("chatter", 1000); ros::Rate loop_rate(10); /** * A count of how many messages we have sent. This is used to create * a unique string for each message. */ int count = 0; while (ros::ok()) { /** * This is a message object. You stuff it with data, and then publish it. */ // float x= 1.0; //std_msgs::String msg; geometry_msgs::Pose2D msg; ReadPoint(); msg.x = getPositionX(); msg.y = getPositionY(); msg.theta = getReady(); ROS_INFO("%f %f %f", msg.x, msg.y, msg.theta); /** * The publish() function is how you send messages. The parameter * is the message object. The type of this object must agree with the type * given as a template parameter to the advertise<>() call, as was done * in the constructor above. */ pose2D_pub.publish(msg); ros::spinOnce(); loop_rate.sleep(); ++count; } return 0; }
unsigned char* QgsMssqlGeometryParser::ParseSqlGeometry( unsigned char* pszInput, int nLen ) { if ( nLen < 10 ) { QgsDebugMsg( "ParseSqlGeometry not enough data" ); DumpMemoryToLog( "Not enough data", pszInput, nLen ); return NULL; } pszData = pszInput; nWkbMaxLen = nLen; /* store the SRS id for further use */ nSRSId = ReadInt32( 0 ); if ( ReadByte( 4 ) != 1 ) { QgsDebugMsg( "ParseSqlGeometry corrupt data" ); DumpMemoryToLog( "Corrupt data", pszInput, nLen ); return NULL; } chProps = ReadByte( 5 ); if ( chProps & SP_HASZVALUES && chProps & SP_HASMVALUES ) nPointSize = 32; else if ( chProps & SP_HASZVALUES || chProps & SP_HASMVALUES ) nPointSize = 24; else nPointSize = 16; /* store byte order */ chByteOrder = QgsApplication::endian(); pszWkb = new unsigned char[nLen]; // wkb should be less or equal in size nWkbLen = 0; if ( chProps & SP_ISSINGLEPOINT ) { // single point geometry nNumPoints = 1; nPointPos = 6; if ( nLen < 6 + nPointSize ) { delete [] pszWkb; QgsDebugMsg( "ParseSqlGeometry not enough data" ); DumpMemoryToLog( "Not enough data", pszInput, nLen ); return NULL; } CopyPoint( 0 ); } else if ( chProps & SP_ISSINGLELINESEGMENT ) { // single line segment with 2 points nNumPoints = 2; nPointPos = 6; if ( nLen < 6 + 2 * nPointSize ) { delete [] pszWkb; QgsDebugMsg( "ParseSqlGeometry not enough data" ); DumpMemoryToLog( "Not enough data", pszInput, nLen ); return NULL; } // copy byte order CopyBytes( &chByteOrder, 1 ); // copy type int wkbType; if ( chProps & SP_HASZVALUES ) wkbType = QGis::WKBLineString25D; else wkbType = QGis::WKBLineString; CopyBytes( &wkbType, 4 ); // copy point count int iCount = 2; CopyBytes( &iCount, 4 ); // copy points CopyCoordinates( 0 ); CopyCoordinates( 1 ); } else { // complex geometries nNumPoints = ReadInt32( 6 ); if ( nNumPoints <= 0 ) { delete [] pszWkb; return NULL; } // position of the point array nPointPos = 10; // position of the figures nFigurePos = nPointPos + nPointSize * nNumPoints + 4; if ( nLen < nFigurePos ) { delete [] pszWkb; QgsDebugMsg( "ParseSqlGeometry not enough data" ); DumpMemoryToLog( "Not enough data", pszInput, nLen ); return NULL; } nNumFigures = ReadInt32( nFigurePos - 4 ); if ( nNumFigures <= 0 ) { delete [] pszWkb; return NULL; } // position of the shapes nShapePos = nFigurePos + 5 * nNumFigures + 4; if ( nLen < nShapePos ) { delete [] pszWkb; QgsDebugMsg( "ParseSqlGeometry not enough data" ); DumpMemoryToLog( "Not enough data", pszInput, nLen ); return NULL; } nNumShapes = ReadInt32( nShapePos - 4 ); if ( nLen < nShapePos + 9 * nNumShapes ) { delete [] pszWkb; QgsDebugMsg( "ParseSqlGeometry not enough data" ); DumpMemoryToLog( "Not enough data", pszInput, nLen ); return NULL; } if ( nNumShapes <= 0 ) { delete [] pszWkb; return NULL; } // pick up the root shape if ( ParentOffset( 0 ) != 0xFFFFFFFF ) { delete [] pszWkb; QgsDebugMsg( "ParseSqlGeometry corrupt data" ); DumpMemoryToLog( "Not enough data", pszInput, nLen ); return NULL; } // determine the shape type switch ( ShapeType( 0 ) ) { case ST_POINT: ReadPoint( 0 ); break; case ST_LINESTRING: ReadLineString( 0 ); break; case ST_POLYGON: ReadPolygon( 0 ); break; case ST_MULTIPOINT: ReadMultiPoint( 0 ); break; case ST_MULTILINESTRING: ReadMultiLineString( 0 ); break; case ST_MULTIPOLYGON: ReadMultiPolygon( 0 ); break; //case ST_GEOMETRYCOLLECTION: //ReadGeometryCollection(0); //break; default: delete [] pszWkb; QgsDebugMsg( "ParseSqlGeometry unsupported geometry type" ); DumpMemoryToLog( "Unsupported geometry type", pszInput, nLen ); return NULL; } } return pszWkb; }
bool ReplayLogger::UpdateInternal(void) { static bool init=true; if (!Enabled) { init = true; ReadLine(NULL); // close file Enabled = true; } static CatmullRomInterpolator cli; SYSTEMTIME st; GetLocalTime(&st); static double time_lstart = 0; if (init) { time_lstart = 0; } static double time=0; double deltatimereal; bool finished = false; double timelast = time; time = (st.wHour*3600+st.wMinute*60+st.wSecond-time_lstart); deltatimereal = time-timelast; if (init) { time_lstart = time; time = 0; deltatimereal = 0; ReplayTime = 0; cli.Reset(); } ReplayTime += TimeScale*deltatimereal; #if DEBUG_REPLAY TCHAR tutc[20]; Units::TimeToText(tutc, (int)ReplayTime); StartupStore(_T("........ REPLAY: UTC h%s\n"),tutc); #endif double mintime = cli.GetMinTime(); // li_lat.GetMinTime(); if (ReplayTime<mintime) { ReplayTime = mintime; } // if need a new point while (cli.NeedData(ReplayTime)&&(!finished)) { double t1, Lat1, Lon1, Alt1; finished = !ReadPoint(&t1,&Lat1,&Lon1,&Alt1); if (!finished && (t1>0)) { if (!cli.Update(t1,Lon1,Lat1,Alt1)) { break; } } } if (!finished) { double LatX, LonX, AltX, SpeedX, BearingX; double LatX1, LonX1, AltX1; cli.Interpolate(ReplayTime, &LonX, &LatX, &AltX); cli.Interpolate(ReplayTime+0.1, &LonX1, &LatX1, &AltX1); SpeedX = cli.GetSpeed(ReplayTime); DistanceBearing(LatX, LonX, LatX1, LonX1, NULL, &BearingX); if ((SpeedX>0) && (LatX != LatX1) && (LonX != LonX1)) { LockFlightData(); if (init) { flightstats.Reset(); } GPS_INFO.Latitude = LatX; GPS_INFO.Longitude = LonX; GPS_INFO.Speed = SpeedX; GPS_INFO.TrackBearing = BearingX; GPS_INFO.Altitude = AltX; GPS_INFO.BaroAltitude = AltitudeToQNHAltitude(AltX); GPS_INFO.Time = ReplayTime; UnlockFlightData(); } else { // This is required in case the integrator fails, // which can occur due to parsing faults ReplayTime = cli.GetMaxTime(); } } // quit if finished. if (finished) { #if DEBUG_REPLAY StartupStore(_T("......... REPLAY: FINISHED\n")); #endif Stop(); } init = false; return !finished; }
void HpCharactorBinParser::readCommon(HpBinaryReader *reader, char *buffer) { switch (ChrReadingVersion) { case 0x02: case 0x03: m_cur_keyfrm->setTime(reader->ReadByte()); break; default: m_cur_keyfrm->setTime(reader->ReadUInt16()); break; } if (m_cur_keyfrm->getContentType() == HPCONTENTTYPE_NULL) return; if (m_cur_keyfrm->getContentType() == HPCONTENTTYPE_ANIMA) m_cur_keyfrm->setIsTimeInherited(reader->ReadBoolean()); m_cur_keyfrm->setCenter(ReadPoint(reader)); m_cur_keyfrm->setScale(ReadPoint(reader)); m_cur_keyfrm->setSkew(ReadPoint(reader)); m_cur_keyfrm->setRot(reader->ReadSingle()); m_cur_keyfrm->setTrans(ReadPoint(reader)); m_cur_keyfrm->setColor(ReadColor(reader)); reader->ReadString(buffer); CCString* event = buffer[0] ? new CCString(buffer) : NULL; m_cur_keyfrm->setEvent(event); CC_SAFE_RELEASE(event); Byte interp_type = reader->ReadByte(); if (interp_type > 0) { HpInterpHolder* holder = new HpInterpHolder(); m_cur_keyfrm->setInterps(holder); CC_SAFE_RELEASE(holder); if (interp_type == 1) { holder->setCenterInterp(HpLinearInterp::Interp()); holder->setScaleInterp(HpLinearInterp::Interp()); holder->setSkewInterp(HpLinearInterp::Interp()); holder->setRotInterp(HpLinearInterp::Interp()); holder->setTransInterp(HpLinearInterp::Interp()); holder->setColorInterp(HpLinearInterp::Interp()); }else if (interp_type == 2) { HpInterp* interp = ReadInterp(reader); holder->setCenterInterp(interp); holder->setScaleInterp(interp); holder->setSkewInterp(interp); holder->setRotInterp(interp); holder->setTransInterp(interp); holder->setColorInterp(interp); }else if (interp_type == 3) { holder->setCenterInterp(ReadInterp(reader)); holder->setScaleInterp(ReadInterp(reader)); holder->setSkewInterp(ReadInterp(reader)); holder->setRotInterp(ReadInterp(reader)); holder->setTransInterp(ReadInterp(reader)); holder->setColorInterp(ReadInterp(reader)); } } }