/** @brief Extract bounding box from shape * * get bounding box as OGREnvelope from polygon shape in OGRFeature */ OGREnvelope* getBBoxOfShape(OGRFeature* poFeature) { OGRGeometry *poGeometry; poGeometry = poFeature->GetGeometryRef(); cout <<"extracting shape of " << poFeature->GetFieldAsString(1) << endl; if (poGeometry != NULL && wkbFlatten(poGeometry->getGeometryType()) == wkbPolygon) { OGRPolygon *poPoly = (OGRPolygon *) poGeometry; OGREnvelope *poEnv = new OGREnvelope(); poPoly->getEnvelope(poEnv); return poEnv; // ofstream outfile ("outfile.kml"); // double s = poEnv->MaxY; // double n = poEnv->MinY; // double e = poEnv->MaxX; // double w = poEnv->MinX; // // cout<< s << ", " << n << " to " << e << ", " << w << endl; // outfile.close(); // cout << poPoint->getX() <<", "<<poPoint->getY()<<endl; } else { cout << "No point Geometry"<<endl; return NULL; } }
void report_raster_data_within_polygon(Raster* raster, OGRPolygon* poPolygon, int feature_num, string feature_name) { if (raster->rasterBBox->Intersects( poPolygon ) ) { OGRPolygon *poIntersection = (OGRPolygon*) raster->rasterBBox->Intersection( poPolygon ); OGREnvelope* envl = new OGREnvelope; poIntersection->getEnvelope(envl); //printf ("Bounding rect (minX, maxX; minY, maxY): %.3f, %.3f; %.3f, %.3f\n", envl->MinX, envl->MaxX, envl->MinY, envl->MaxY); const double pw = raster->pixel_width; const double ph = raster->pixel_height; int pixelOffset_X = round((envl->MinX - raster->upper_left_x) / pw); int pixelOffset_Y = round((raster->upper_left_y - envl->MaxY) / ph); int nCellsX = round((envl->MaxX - raster->upper_left_x) / pw) - pixelOffset_X; int nCellsY = round((raster->upper_left_y - envl->MinY) / ph) - pixelOffset_Y; OGRPoint* pixelPoint = new OGRPoint(0,0); float* pPixelValue = (float *) CPLMalloc(sizeof(float)); cerr << "Feature size: " << nCellsX << "x" << nCellsY << endl; for ( int row = 0; row < nCellsY; ++row ) { for ( int col = 0; col < nCellsX; ++col ) { double xcenter = (col + pixelOffset_X + 0.5)*pw + raster->upper_left_x; double ycenter = raster->upper_left_y - (row + pixelOffset_Y + 0.5)*ph; pixelPoint->setX(xcenter); pixelPoint->setY(ycenter); if ( pixelPoint->Intersects(poPolygon)) { raster->band->RasterIO( GF_Read, pixelOffset_X + col, pixelOffset_Y + row, 1,1, pPixelValue, 1,1, GDT_Float32, 0, 0 ); cout << setprecision(10) << xcenter << "," << setprecision(10) << ycenter << "," << *pPixelValue << "," << feature_num << "," << feature_name << endl; } } } delete envl; CPLFree(pPixelValue); } else { cerr << "Feature does not intersect raster" << endl; } return; }
GDAL_GCP * PrepareGCP(const CPLString& sFileName, OGRPoint *pt1, OGRPoint *pt2, OGRPoint *pt3, OGRPoint *pt4, OGRPoint *ptCenter, const OGRSpatialReference &oDstOGRSpatialReference, const int nRasterSizeX, const int nRasterSizeY, int &nGCPCount, OGREnvelope &DstEnv) { // to meters double dfFocusM = dfFocus / 100; double dfFilmHalfHeightM = dfFilmHeight / 200; double dfRatio = dfFilmHalfHeightM / dfFocusM; //create center point and line of scene OGRPoint ptShortSideBeg = GetCenterOfLine(pt1, pt4); OGRPoint ptShortSideEnd = GetCenterOfLine(pt2, pt3); OGRLineString lnTmp; lnTmp.addPoint(&ptShortSideBeg); lnTmp.addPoint(&ptShortSideEnd); lnTmp.Value(lnTmp.Project(pt1), &ptShortSideBeg); lnTmp.Value(lnTmp.Project(pt2), &ptShortSideEnd); double dfDist1 = pt1->Distance(pt2); double dfDist2 = pt2->Distance(pt3); double dfDist3 = pt3->Distance(pt4); double dfDist4 = pt4->Distance(pt1); double dfHalfWidth = (dfDist2 + dfDist4) / 4; double dfHalfHeight = (dfDist1 + dfDist3) / 4; double dfAltitudeAtSide = (dfHalfWidth * dfFocusM) / dfFilmHalfHeightM; double dfAltitudeAtSceneCenter = sqrt( dfAltitudeAtSide * dfAltitudeAtSide - dfHalfHeight * dfHalfHeight); double dfAltitude = dfAltitudeAtSceneCenter * cos(dfMountAngleRad); // 145 - 220 km double dfDistCenter = dfAltitudeAtSceneCenter * sin(dfMountAngleRad); OGRLineString lnCenterLeft; lnCenterLeft.addPoint(&ptShortSideBeg); lnCenterLeft.addPoint(ptCenter); OGRPoint ptSatCenter = GetTangetPoint(lnCenterLeft, dfDistCenter); std::vector<OGRPoint> aPt1, aPt2; int nTotalGCPCount = ((SEGMENT_STEPS + 1) * 2); GDAL_GCP *paGSPs = (GDAL_GCP *) CPLMalloc (nTotalGCPCount * sizeof(GDAL_GCP)); GDALInitGCPs(nTotalGCPCount, paGSPs); double dfImageStepLen = double(nRasterSizeX) / SEGMENT_STEPS; double dfImageCenterX = 0; OGRLineString lnCenter; lnCenter.addPoint(&ptShortSideBeg); lnCenter.addPoint(ptCenter); lnCenter.addPoint(&ptShortSideEnd); double dfCenterLineLen = lnCenter.get_Length(); double dfStepLen = dfCenterLineLen / SEGMENT_STEPS; double dfCenterLineHalfLen = dfCenterLineLen / 2; for(double i = 0; i <= dfCenterLineLen; i += dfStepLen) { OGRPoint ptTmp; lnCenter.Value(i, &ptTmp); double dfDist = fabs(dfCenterLineHalfLen - i); double dfWidthTmp = GetWidthForHeight(dfAltitudeAtSceneCenter, dfDist, dfRatio); OGRLineString lnTmpLine; lnTmpLine.addPoint(ptCenter); lnTmpLine.addPoint(&ptTmp); int direction = 1; if(dfCenterLineHalfLen < i) direction = -1; OGRPoint ptUp = GetTangetPoint(lnTmpLine, dfWidthTmp * direction); OGRPoint ptDown = GetTangetPoint(lnTmpLine, -dfWidthTmp * direction); //OGRPoint ptUp = GetValue(dfWidthTmp, lnTmpLine); //OGRPoint ptDown = GetValue(-dfWidthTmp, lnTmpLine); aPt1.push_back(ptUp); aPt2.push_back(ptDown); paGSPs[nGCPCount].dfGCPLine = 0; paGSPs[nGCPCount].dfGCPPixel = dfImageCenterX; paGSPs[nGCPCount].dfGCPX = ptDown.getX(); paGSPs[nGCPCount].dfGCPY = ptDown.getY(); paGSPs[nGCPCount].dfGCPZ = dfMeanHeight; paGSPs[nGCPCount].pszId = CPLStrdup(CPLSPrintf("pt%d", nGCPCount)); nGCPCount++; paGSPs[nGCPCount].dfGCPLine = nRasterSizeY; paGSPs[nGCPCount].dfGCPPixel = dfImageCenterX; paGSPs[nGCPCount].dfGCPX = ptUp.getX(); paGSPs[nGCPCount].dfGCPY = ptUp.getY(); paGSPs[nGCPCount].dfGCPZ = dfMeanHeight; paGSPs[nGCPCount].pszId = CPLStrdup(CPLSPrintf("pt%d", nGCPCount)); nGCPCount++; dfImageCenterX += dfImageStepLen; } // add points to polygon OGRLinearRing Ring; for(int i = 0; i < aPt1.size(); ++i) Ring.addPoint(aPt1[i].getX(), aPt1[i].getY()); for(int i = aPt2.size() - 1; i >= 0; --i) Ring.addPoint(aPt2[i].getX(), aPt2[i].getY()); Ring.closeRings(); OGRPolygon Rgn; Rgn.addRingDirectly((OGRCurve*)Ring.clone()); Rgn.assignSpatialReference(oDstOGRSpatialReference.Clone()); Rgn.flattenTo2D(); Rgn.getEnvelope(&DstEnv); SaveGeometry(CPLResetExtension(sFileName, "shp"), Rgn, oDstOGRSpatialReference); return paGSPs; }
void LevelTerrainCallback::loaded(osgTerrain::TerrainTile *tile, const osgDB::ReaderWriter::Options *options) const { //Change TerrainTechnique tile->setTerrainTechnique(new DecoratedGeometryTechnique(voidBoundingAreaVector, treeStateSet.get(), buildingStateSet.get(), shapeFileVector)); std::stringstream nameStream; nameStream << "tile_L" << tile->getTileID().level << "_X" << tile->getTileID().x << "_Y" << tile->getTileID().y; tile->setName(nameStream.str()); /*tile->setName("TerrainTile"); osg::Vec3d model; tile->getLocator()->convertLocalToModel(osg::Vec3d(0.0,0.0,0.0), model); char name[1000]; sprintf(name,"X%f_Y%f_Z%f", model.x(), model.y(), model.z()); tile->setName(name);*/ //MTRand mt(10101); osgTerrain::HeightFieldLayer *hflayer = dynamic_cast<osgTerrain::HeightFieldLayer *>(tile->getElevationLayer()); osg::HeightField *field = NULL; if (hflayer) { field = hflayer->getHeightField(); } else { return; } double tileXInterval = field->getXInterval(); double tileYInterval = field->getYInterval(); double tileElementArea = tileXInterval * tileYInterval; double tileXMin = offset.x() + field->getOrigin().x(); double tileXMax = tileXMin + tileXInterval * (double)field->getNumColumns(); double tileYMin = offset.y() + field->getOrigin().y(); double tileYMax = tileYMin + tileYInterval * (double)field->getNumRows(); //osg::BoundingBox tileBB(tileXMin, tileYMin, -10.000, tileXMax, tileYMax, 10.000); if (tileXInterval > 10.0 && tileYInterval > 10.0) { return; } for (int i = 0; i < RoadSystem::Instance()->getNumRoads(); ++i) { Road *road = RoadSystem::Instance()->getRoad(i); double roadLength = road->getLength(); const osg::BoundingBox &roadBB = road->getRoadGeode()->getBoundingBox(); //if(roadBB.intersects(tileBB)) { if (((roadBB.xMax() >= tileXMin && roadBB.xMax() <= tileXMax) || (roadBB.xMin() >= tileXMin && roadBB.xMin() <= tileXMax) || (roadBB.xMin() <= tileXMin && roadBB.xMax() >= tileXMax)) && (roadBB.yMax() >= tileYMin && roadBB.yMin() <= tileYMax)) { //double h = sqrt(tileXInterval*tileXInterval + tileYInterval*tileYInterval); double h = 20.0; std::deque<RoadPoint> pointDeque(4); double widthRight, widthLeft; road->getRoadSideWidths(0.0, widthRight, widthLeft); pointDeque.pop_front(); pointDeque.pop_front(); pointDeque.push_back(road->getRoadPoint(0.0, widthLeft + 10.0)); pointDeque.push_back(road->getRoadPoint(0.0, widthRight - 10.0)); std::map<std::pair<int, int>, double> coordHeightMap; for (double s_ = h; s_ < roadLength + h; s_ = s_ + h) { double s = s_; if (s > roadLength) s = roadLength; road->getRoadSideWidths(s, widthRight, widthLeft); pointDeque.pop_front(); pointDeque.pop_front(); pointDeque.push_back(road->getRoadPoint(s, widthLeft + 10.0)); pointDeque.push_back(road->getRoadPoint(s, widthRight - 10.0)); //Bresenham // y x z std::map<int, std::map<int, double> > fillBorderMap; //iteration over four lines for (int i = 0; i < 4; ++i) { int j; switch (i) { case 0: j = 1; break; case 1: j = 3; break; case 2: j = 0; break; case 3: j = 2; break; } double fx0 = (pointDeque[i].x() - tileXMin) / tileXInterval; double fy0 = (pointDeque[i].y() - tileYMin) / tileYInterval; double fx1 = (pointDeque[j].x() - tileXMin) / tileXInterval; double fy1 = (pointDeque[j].y() - tileYMin) / tileYInterval; double dir_x = (fx0 - fx1) < 0.0 ? -1.0 : 1.0; double dir_y = (fy0 - fy1) < 0.0 ? -1.0 : 1.0; int x0 = (int)floor(fx0 + dir_x + 0.5); //if(x0<0) x0=0; else if(x0>=field->getNumColumns()) x0=field->getNumColumns()-1; int y0 = (int)floor(fy0 + dir_y + 0.5); //if(y0<0) y0=0; else if(y0>=field->getNumRows()) y0=field->getNumRows()-1; int x1 = (int)floor(fx1 - dir_x + 0.5); //if(x1<0) x1=0; else if(x1>=field->getNumColumns()) x1=field->getNumColumns()-1; int y1 = (int)floor(fy1 - dir_y + 0.5); //if(y1<0) y1=0; else if(y1>=field->getNumRows()) y1=field->getNumRows()-1; double z = 0.5 * (pointDeque[i].z() + pointDeque[j].z()); //wikipedia implementation int dx = abs(x1 - x0); int sx = x0 < x1 ? 1 : -1; int dy = -abs(y1 - y0); int sy = y0 < y1 ? 1 : -1; int err = dx + dy; int e2; /* error value e_xy */ do { /* loop */ //setPixel(x0,y0); fillBorderMap[y0][x0] = z; //fillBorderMap[y0][x0] = 0.5; //if (x0==x1 && y0==y1) break; e2 = 2 * err; if (e2 >= dy) { err += dy; x0 += sx; } /* e_xy+e_x > 0 */ if (e2 <= dx) { err += dx; y0 += sy; } /* e_xy+e_y < 0 */ } while (!(x0 == x1 && y0 == y1)); } for (std::map<int, std::map<int, double> >::iterator yScanlineIt = fillBorderMap.begin(); yScanlineIt != fillBorderMap.end(); ++yScanlineIt) { int x0 = (yScanlineIt->second.begin())->first; double z0 = (yScanlineIt->second.begin())->second; int x1 = (--(yScanlineIt->second.end()))->first; double z1 = (--(yScanlineIt->second.end()))->second; unsigned int y = yScanlineIt->first; //if(y==field->getNumRows()-1) continue; for (int x = x0; x <= x1; ++x) { if (x >= 0 && x < (int)field->getNumColumns() && y >= 0 && y < field->getNumRows()) { //field->setHeight(x,y,0.5*(z0+z1)-0.5); //double z = field->getHeight(x,y); double rl_x = 0.5 * (pointDeque[0].x() + pointDeque[1].x()); double rl_y = 0.5 * (pointDeque[0].y() + pointDeque[1].y()); double ru_x = 0.5 * (pointDeque[2].x() + pointDeque[3].x()); double ru_y = 0.5 * (pointDeque[2].y() + pointDeque[3].y()); double t_x = ru_x - rl_x; double t_y = ru_y - rl_y; double mag_t = sqrt(t_x * t_x + t_y * t_y); if (mag_t != mag_t) continue; t_x /= mag_t; t_y /= mag_t; double rp_x = tileXInterval * ((double)(x)) + tileXMin - rl_x; double rp_y = tileYInterval * ((double)(y)) + tileYMin - rl_y; double d_x = -t_y * t_x * rp_y + t_y * t_y * rp_x; double d_y = t_x * t_x * rp_y - t_x * t_y * rp_x; double d = sqrt(d_x * d_x + d_y * d_y); //double mag_d = sqrt(d_x*d_x + d_y*d_y); //double d = 0.0; //if(mag_d==mag_d) { // d = (d_x*d_x+d_y*d_y)/mag_d; //} double s_x = rp_x - d_x; double s_y = rp_y - d_y; double s = sqrt(s_x * s_x + s_y * s_y); double wl = sqrt(pow(pointDeque[0].x() - pointDeque[1].x(), 2) + pow(pointDeque[0].y() - pointDeque[1].y(), 2)); double wu = sqrt(pow(pointDeque[2].x() - pointDeque[3].x(), 2) + pow(pointDeque[2].y() - pointDeque[3].y(), 2)); double l = sqrt(pow(0.5 * (pointDeque[0].x() - pointDeque[2].x() + pointDeque[1].x() - pointDeque[3].x()), 2) + pow(0.5 * (pointDeque[0].y() - pointDeque[2].y() + pointDeque[1].y() - pointDeque[3].y()), 2)); double zt; std::map<std::pair<int, int>, double>::iterator coordHeightMapIt = coordHeightMap.find(std::make_pair(x, y)); if (coordHeightMapIt == coordHeightMap.end()) { zt = (double)field->getHeight(x, y); coordHeightMap[std::make_pair(x, y)] = zt; } else { zt = coordHeightMapIt->second; } double zf0 = 7.0; double zf = 0.5 * (z0 + z1) - zf0; double kt0 = 50.0; double kt = (d / (0.5 * (wl + (wu - wl) * s / l))) * kt0; double kf0 = 10.0; double kf = (1.0 - d / (0.5 * (wl + (wu - wl) * s / l))) * kf0; double zl = (zt * kt + zf * kf) / (kt + kf); double z_field = field->getHeight(x, y); if (z_field > zl) { field->setHeight(x, y, zl); } //std::cout << "(x,y): (" << x << "," << y << "), zt: " << zt << ", zf: " << zf << ", kt: " << kt << ", kf: " << kf << std::endl; //field->setHeight(x,y, std::min(zf, 0.5*(z0+z1) - 1.0*(1.0- d/(wl+(wu-wl)*s/l)) ) ); //std::cout << "(x,y): (" << x << "," << y << "), z0: " << z0 << ", z1: " << z1 << ", d: " << d << ", wl: " << wl << ", wu: " << wu << ", s: " << s << ", l: " << l << std::endl; } } } /*Vector3D roadCenterPoint = road->getCenterLinePoint(s); int x = floor((roadCenterPoint.x() - tileXMin)/tileXInterval + 0.5); int y = floor((roadCenterPoint.y() - tileYMin)/tileYInterval + 0.5); if(x>=0 && x<field->getNumColumns() && y>=0 && y<field->getNumRows()) { field->setHeight(x,y,0.0); }*/ } } } #if 0 //osg::Group* treeGroup = new osg::Group(); //tile->addChild(treeGroup); //treeGroup->setName("TreeGroup"); osg::PositionAttitudeTransform* treeGeodeTransform = new osg::PositionAttitudeTransform; tile->addChild(treeGeodeTransform); treeGeodeTransform->setName("TreeGeodeTransform"); osg::Vec3 tileMin(tileXMin, tileYMin, 0.0); treeGeodeTransform->setPosition(-offset + tileMin); osg::Geode* treeGeode = new osg::Geode(); //tile->addChild(treeGeode); treeGeodeTransform->addChild(treeGeode); treeGeode->setName("TreeGeode"); treeGeode->setStateSet(treeStateSet); #endif #if 0 for(int layerIt = 0; layerIt < layers.size(); ++layerIt) { OGRLayer* layer = layers[layerIt]; layer->ResetReading(); OGRFeature* poFeature = NULL; while((poFeature = layer->GetNextFeature()) != NULL) { OGRGeometry *poGeometry = poFeature->GetGeometryRef(); if(poGeometry != NULL && wkbFlatten(poGeometry->getGeometryType()) == wkbPolygon) { OGRPolygon *poPolygon = dynamic_cast<OGRPolygon*>(poGeometry); //std::cout << "Geometry name: " << poPolygon->getGeometryName() << std::endl; //std::cout << "Polgon area: " << poPolygon->get_Area() << std::endl; OGRSpatialReference *poSource = layer->GetSpatialRef(); OGRSpatialReference *poTarget = new OGRSpatialReference(); poTarget->importFromProj4("+proj=utm +zone=32"); OGRCoordinateTransformation* poCoordTrans = OGRCreateCoordinateTransformation(poSource, poTarget); poPolygon->transform(poCoordTrans); OGRLinearRing* poRing = poPolygon->getExteriorRing(); /*for(int pointIt = 0; pointIt<poRing->getNumPoints(); ++pointIt) { std::cout << "Point " << pointIt << ": (" << poRing->getX(pointIt) + offset.x() << ", " << poRing->getY(pointIt) + offset.y() << ", " << poRing->getZ(pointIt) << ")" << std::endl; }*/ /*double interval = 10.0*sqrt(tileXInterval*tileXInterval + tileYInterval*tileYInterval); OGRPoint point; poRing->Value(0, &point); OGRPoint point_next; for(double s = 0; s<poRing->get_Length(); s += interval*mt()) { double s_next = s+interval; if(s_next>poRing->get_Length()) s_next = poRing->get_Length(); poRing->Value(s_next, &point_next); double ccw = poRing->isClockwise() ? -1.0 : 1.0; double t_x = point_next.getX() - point.getX(); double t_y = point_next.getY() - point.getY(); double n_x = -t_y*ccw; double n_y = t_x*ccw; double mag_n = sqrt(n_x*n_x+n_y*n_y); if(mag_n>1e-3) { n_x /= mag_n; n_y /= mag_n; } double n_mt = mt(); double x = point.getX()+offset.x() + 0.5*t_x + 10.0*n_mt*n_x; double y = point.getY()+offset.y() + 0.5*t_y + 10.0*n_mt*n_y; //std::cout << "t_x: " << t_x << ", t_y: " << t_y << ", n_x: " << 10.0*n_mt*n_x << ", n_y: " << 10.0*n_mt*n_y << std::endl; std::cout << "x: " << x << ", y: " << y << std::endl; point = point_next; //std::cout << "Boundary trace: s: " << s << ", x: " << x << ", y:" << y << ", tile min: (" << tileXMin << ", " << tileYMin << "), max: (" << tileXMax << ", " << tileYMax << ")" << std::endl; osg::BoundingBox tileBB(tileXMin, tileYMin, -1.0, tileXMax, tileYMax, 1.0); if(tileBB.contains(osg::Vec3(x,y,0.0))) { osg::PositionAttitudeTransform* treeTrans = new osg::PositionAttitudeTransform(); treeGroup->addChild(treeTrans); //hflayer->getInterpolatedValue(x,y,z); int x_int = floor((x-tileXMin)/tileXInterval+0.5); if(x_int<0) x_int=0; else if(x_int>=field->getNumColumns()) x_int=field->getNumColumns()-1; int y_int = floor((y-tileYMin)/tileYInterval+0.5); if(y_int<0) y_int=0; else if(y_int>=field->getNumRows()) y_int=field->getNumRows()-1; double z = field->getHeight(x_int,y_int); //osg::Vec3 treePos(x,y,z); osg::Vec3 treePos(point.getX(),point.getY(),z); treeTrans->setPosition(treePos); int treeIt = (int)floor(mt()*(double)treeNodeVector.size()); treeTrans->addChild(treeNodeVector[treeIt].get()); treeTrans->setName("TreeTransform"); } }*/ OGREnvelope psEnvelope; poPolygon->getEnvelope(&psEnvelope); int nTrees = (int)((psEnvelope.MaxX-psEnvelope.MinX)*(psEnvelope.MaxY-psEnvelope.MinY)*1e-5/tileElementArea); for(int i = 0; i<nTrees; ++i) { OGRPoint point; //point.setX(mt()*(psEnvelope.MaxX-psEnvelope.MinX) + psEnvelope.MinX); //point.setY(mt()*(psEnvelope.MaxY-psEnvelope.MinY) + psEnvelope.MinY); point.setX(mt()*(tileXMax-tileXMin) + tileXMin); point.setY(mt()*(tileYMax-tileYMin) + tileYMin); //if(poPolygon->Contains(&point)) { osg::PositionAttitudeTransform* treeTrans = new osg::PositionAttitudeTransform(); treeGroup->addChild(treeTrans); //hflayer->getInterpolatedValue(x,y,z); double x = point.getX() + offset.x(); double y = point.getY() + offset.y(); int x_int = floor((x-tileXMin)/tileXInterval+0.5); if(x_int<0) x_int=0; else if(x_int>=field->getNumColumns()) x_int=field->getNumColumns()-1; int y_int = floor((y-tileYMin)/tileYInterval+0.5); if(y_int<0) y_int=0; else if(y_int>=field->getNumRows()) y_int=field->getNumRows()-1; double z = field->getHeight(x_int,y_int); std::cout << "int x: " << x_int << ", x: " << x-tileXMin << ", y: " << y_int << ", y: " << y-tileYMin << std::endl; //osg::Vec3 treePos(x,y,z); osg::Vec3 treePos(x,y,z); treeTrans->setPosition(treePos); int treeIt = (int)floor(mt()*(double)treeNodeVector.size()); treeTrans->addChild(treeNodeVector[treeIt].get()); treeTrans->setName("TreeTransform"); //} } } } } #endif #if 0 typedef gaalet::algebra< gaalet::signature<3,0> > em; typedef em::mv<1, 2, 4>::type Vector; typedef em::mv<3, 5, 6>::type Bivector; typedef em::mv<0, 3, 5, 6>::type Rotor; static const em::mv<0>::type one(1.0); static const em::mv<1>::type e1(1.0); static const em::mv<2>::type e2(1.0); static const em::mv<4>::type e3(1.0); static const em::mv<7>::type e123(1.0); osgTerrain::Layer* colorLayer = tile->getColorLayer(0); if(colorLayer) { osg::Image* inputImage = colorLayer->getImage(); /*static int tileLoadCounter = 0; osg::Image* outputImage = NULL; if(tileLoadCounter==0) { outputImage = new osg::Image(); outputImage->allocateImage(inputImage->s(), inputImage->t(), 1, 0x1907, 0x1401); } tileLoadCounter += 1;*/ em::mv<0,6>::type *fftwImag1 = (em::mv<0,6>::type*) fftw_malloc(sizeof(em::mv<0,6>::type)*inputImage->s()*inputImage->t()); em::mv<0,3>::type *fftwImag2 = (em::mv<0,3>::type*) fftw_malloc(sizeof(em::mv<0,3>::type)*inputImage->s()*inputImage->t()); em::mv<0,6>::type *fftwFreq1 = (em::mv<0,6>::type*) fftw_malloc(sizeof(em::mv<0,6>::type)*inputImage->s()*inputImage->t()); em::mv<0,3>::type *fftwFreq2 = (em::mv<0,3>::type*) fftw_malloc(sizeof(em::mv<0,3>::type)*inputImage->s()*inputImage->t()); fftw_plan fftwForward1 = fftw_plan_dft_2d(inputImage->s(), inputImage->t(), reinterpret_cast<fftw_complex*>(fftwImag1), reinterpret_cast<fftw_complex*>(fftwFreq1), FFTW_FORWARD, FFTW_ESTIMATE); fftw_plan fftwForward2 = fftw_plan_dft_2d(inputImage->s(), inputImage->t(), reinterpret_cast<fftw_complex*>(fftwImag2), reinterpret_cast<fftw_complex*>(fftwFreq2), FFTW_FORWARD, FFTW_ESTIMATE); fftw_plan fftwBackward1 = fftw_plan_dft_2d(inputImage->s(), inputImage->t(), reinterpret_cast<fftw_complex*>(fftwFreq1), reinterpret_cast<fftw_complex*>(fftwImag1), FFTW_BACKWARD, FFTW_ESTIMATE); fftw_plan fftwBackward2 = fftw_plan_dft_2d(inputImage->s(), inputImage->t(), reinterpret_cast<fftw_complex*>(fftwFreq2), reinterpret_cast<fftw_complex*>(fftwImag2), FFTW_BACKWARD, FFTW_ESTIMATE); for(int x=0; x<inputImage->s(); ++x) { for(int y=0; y<inputImage->t(); ++y) { if(inputImage->getPixelFormat()==0x83f0) { //COMPRESSED_RGB_S3TC_DXT1_EXT decompression unsigned int blocksize = 8; unsigned char* data = inputImage->data(); unsigned char* block = data + (blocksize*(unsigned int)(ceil(double(inputImage->s()/4.0)*floor(y/4.0) + floor(x/4.0)))); int rel_x = x % 4; int rel_y = y % 4; unsigned char& c0_lo = *(block+0); unsigned char& c0_hi = *(block+1); unsigned char& c1_lo = *(block+2); unsigned char& c1_hi = *(block+3); unsigned char& bits_0 = *(block+4); unsigned char& bits_1 = *(block+5); unsigned char& bits_2 = *(block+6); unsigned char& bits_3 = *(block+7); unsigned short color0 = c0_lo + c0_hi * 256; unsigned short color1 = c1_lo + c1_hi * 256; unsigned int bits = bits_0 + 256 * (bits_1 + 256 * (bits_2 + 256 * bits_3)); unsigned int code_bits_pos = 2*(4*rel_y+rel_x); unsigned int code = (bits>>code_bits_pos) & 0x03; unsigned char r0 = ((color0>>11) & 0x1f); unsigned char g0 = ((color0>>5) & 0x3f); unsigned char b0 = ((color0>>0) & 0x1f); unsigned char r1 = ((color1>>11) & 0x1f); unsigned char g1 = ((color1>>5) & 0x3f); unsigned char b1 = ((color1>>0) & 0x1f); unsigned char r = 0; unsigned char g = 0; unsigned char b = 0; if(color0>color1) { switch(code) { case 0: r = r0; g = g0; b = b0; break; case 1: r = r1; g = g1; b = b1; break; case 2: r = (2*r0+r1)/3; g = (2*g0+g1)/3; b = (2*b0+b1)/3; break; case 3: r = (r0+2*r1)/3; g = (g0+2*g1)/3; b = (b0+2*b1)/3; break; }; } else { switch(code) { case 0: r = r0; g = g0; b = b0; break; case 1: r = r1; g = g1; b = b1; break; case 2: r = (r0+r1)/2; g = (g0+g1)/2; b = (b0+b1)/2; break; case 3: r = 0; g = 0; b = 0; break; }; } (*(fftwImag1+inputImage->t()*x+y)) = (0.0*one)+((double)r*(double)0xff/(double)0x1f*e2*e3); (*(fftwImag2+inputImage->t()*x+y)) = ((double)g*(double)0xff/(double)0x3f*e3*e1)*e3*e1 + ((double)b*(double)0xff/(double)0x1f*e1*e2); /*if(outputImage) { *(outputImage->data(x,y)+0) = (unsigned int)((double)r*(double)0xff/(double)0x1f); *(outputImage->data(x,y)+1) = (unsigned int)((double)g*(double)0xff/(double)0x3f); *(outputImage->data(x,y)+2) = (unsigned int)((double)b*(double)0xff/(double)0x1f); }*/ } else { unsigned char& r = *(inputImage->data(x,y)+0); unsigned char& g = *(inputImage->data(x,y)+1); unsigned char& b = *(inputImage->data(x,y)+2); (*(fftwImag1+inputImage->t()*x+y)) = (0.0*one)+((double)r*e2*e3); (*(fftwImag2+inputImage->t()*x+y)) = ((double)g*e3*e1)*e3*e1 + ((double)b*e1*e2); //if(x==0 && y==0) std::cout << "(0,0): r: " << (int)r << ", g: " << (int)g << ", b: " << (int)b << std::endl; } } }