void GrayScaleImagesFVProducer::SaveIntermediateImage (const Raster& raster, const KKStr& desc, RasterListPtr intermediateImages ) { if (!intermediateImages) return; RasterPtr newRaster = NULL; kkint32 largestDim = Max (raster.Height (), raster.Width ()); if (largestDim < 300) { newRaster = new Raster (raster); } else { kkint32 reductionMultiple = 2; while ((largestDim / reductionMultiple) > 300) reductionMultiple++; newRaster = raster.ReduceByEvenMultiple (reductionMultiple); } newRaster->FileName (desc); intermediateImages->PushOnBack (newRaster); } /* SaveIntermediateImage */
void point_test(Pixel *PixelBuffer) { Points points = { { 1 , 5 }, { 28, 90 }, { 48, 49 }, { 93, 26 }, }; Points sorted = points; Raster raster; Point p; std::sort(sorted.begin(), sorted.end(), point_sortable); point_print_vec(&points); point_print_vec(&sorted); Points *p_max_min = raster.points_max_min(&points); point_print_vec(p_max_min); std::cout << "Adding "; point_print(sorted[0]); std::cout << " to "; point_print(sorted[1]); std::cout << "\n"; point_print(sorted[0]+sorted[1]); delete(p_max_min); }
GraphicComp* ImportCmd::PGM_Image (const char* filename) { GraphicComp* comp = nil; FILE* file = fopen(filename, "r"); if (file != nil) { char line[1000]; do { fgets(line, 1000, file); } while (strcmp(line, "gsave\n") != 0); fgets(line, 1000, file); // translate fgets(line, 1000, file); // scale fgets(line, 1000, file); // sizes int w, h, d; sscanf(line, "%d %d %d", &w, &h, &d); fgets(line, 1000, file); // [ ... ] fgets(line, 1000, file); // { ... } fgets(line, 1000, file); // image Raster* raster = new Raster(w, h); for (int row = h - 1; row >= 0; --row) { for (int column = 0; column < w; ++column) { int byte = gethex(file); float g = float(byte) / 0xff; raster->poke(column, row, g, g, g, 1.0); } } raster->flush(); comp = new RasterComp(new RasterRect(raster), filename); } fclose(file); return comp; }
int main(int argc, char* argv[]) { Raster* raster = nullptr; CommandLineParameter cmd(argc, argv); srand(time(NULL)); if (!cmd.patternFilename.empty()) { raster = new Raster(cmd.patternFilename); } else { raster = new Raster(cmd.width, cmd.height, cmd.seedProbability); } for (int iteration = 0; iteration <= cmd.maxIterations; iteration++) { raster->save(cmd.outputDirectory + "game_of_life_" + std::to_string(iteration) + ".bmp"); simulateInvasion(*raster, cmd.invasionFactor); simulateNextState(*raster, cmd.isTorus); } delete raster; return 0; }
void cohen_test(Pixel *PixelBuffer) { Raster raster; Points bounds; bounds.push_back({ 10, 10 }); bounds.push_back({ 10, 100 }); bounds.push_back({ 100, 100 }); bounds.push_back({ 100, 10 }); Points shape; shape.push_back({ 5, 5 }); shape.push_back({ 50, 115 }); View view = View(SCREENSIZE, SCREENSIZE, PixelBuffer); Points *p = raster.cohen_sutherland(&bounds, &shape); if (p != NULL) { Points *r = Bresenham(p->at(0), p->at(1)); view.update_buffer(r); delete r; } else { std::cout << "NOPE< NULLLLLL\n"; } delete p; }
NativeGUIWin CmapEditGUI::Construct(void) { int TabIndex, Pos; Raster *MyRast; if(!NativeWin) { NativeWin = CreateWinFromTemplate(WCS_FENETRE_GENERIC_EDIT_TEMPLATE, LocalWinSys()->RootWin); CreateSubWinFromTemplate(IDD_CMAP_GENERAL, 0, 0); CreateSubWinFromTemplate(IDD_CMAP_ECOSYSTEMS, 0, 1); if(NativeWin) { for (TabIndex = 0; TabIndex < WCS_CMAPGUI_NUMTABS; TabIndex ++) { WidgetTCInsertItem(IDC_TAB1, TabIndex, TabNames[TabIndex]); } // for WidgetTCSetCurSel(IDC_TAB1, ActivePage); WidgetCBInsert(IDC_IMAGEDROP, -1, "New Image Object..."); for (MyRast = GlobalApp->AppImages->GetFirstRast(); MyRast; MyRast = GlobalApp->AppImages->GetNextRast(MyRast)) { if(MyRast->MatchAttribute(WCS_RASTERSHELL_TYPE_GEOREF)) { Pos = WidgetCBInsert(IDC_IMAGEDROP, -1, MyRast->GetUserName()); WidgetCBSetItemData(IDC_IMAGEDROP, Pos, MyRast); } // if } // for ShowPanel(0, ActivePage); ConfigureWidgets(); } // if } // if return (NativeWin); } // CmapEditGUI::Construct
int SegmentImpl::process(const SegmentParameters ¶ms, Raster &raster) { raster.scatterHistogram(); raster.resetMarker(); // create empty marker // must be called as the last one // before true segmentation! return segment_image(raster, params, _h); // process image };
Raster* DemAspectProcessorImpl::Aspect(Raster* pinRaster) { Raster* poutRaster = NULL; RasterFactory* pRasterFactory = augeGetRasterFactoryInstance(); //poutRaster = pRasterFactory->CreateRaster("", augePixelDouble, 1, pinRaster->GetExtent(), pinRaster->GetWidth(), pinRaster->GetHeight(), pinRaster->GetSpatialReference()); poutRaster = pRasterFactory->CreateRaster("", augePixelFloat32, 1, pinRaster->GetExtent(), pinRaster->GetWidth(), pinRaster->GetHeight(), pinRaster->GetSpatialReference()); if(poutRaster==NULL) { return NULL; } RESULTCODE rc = AG_SUCCESS; augePixelType type = pinRaster->GetPixelType(); RasterBand* pinBand = NULL; RasterBand* poutBand = NULL; g_uint band_count = pinRaster->GetBandCount(); for(g_uint i=0; i<band_count; i++) { pinBand = pinRaster->GetBand(i); poutBand = poutRaster->GetBand(i); switch(type) { case augePixelByte: rc = Aspect_Byte(pinBand, poutBand); break; case augePixelUInt16: case augePixelInt16: Aspect_Short(pinBand, poutBand); break; case augePixelUInt32: case augePixelInt32: break; case augePixelFloat32: Aspect_Float(pinBand, poutBand); break; case augePixelDouble: Aspect_Double(pinBand, poutBand); break; } if(rc!=AG_SUCCESS) { break; } } if(rc!=AG_SUCCESS) { poutRaster->Release(); poutRaster = NULL; } return poutRaster; }
int Raster<T>::Copy(Raster& otherRaster) { //delete existing memory DeleteExistingData(); m_nRows = otherRaster.GetNumberOfRows(); m_nCols = otherRaster.GetNumberofColumns(); m_xllCenter = otherRaster.GetXllCenter(); m_yllCenter = otherRaster.GetYllCenter(); m_dx = otherRaster.GetXCellSize(); m_dy = otherRaster.GetYCellSize(); m_noDataValue = otherRaster.GetNoDataValue(); m_srs = otherRaster.GetSRS(); //allocate memory m_data = new T*[m_nRows]; for (int i = 0; i < m_nRows; ++i) { m_data[i] = new T[m_nCols]; for (int j = 0; j < m_nCols; ++j) { m_data[i][j] = otherRaster.At(i, j); } } return 0; }
void GrayScaleImagesFVProducer::ReductionByMultiple (kkint32 multiple, const Raster& srcRaster, Raster& destRaster ) { kkint32 srcHeight = srcRaster.Height (); kkint32 srcWidth = srcRaster.Width (); kkint32 destHeight = (srcHeight + multiple - 1) / multiple; kkint32 destWidth = (srcWidth + multiple - 1) / multiple; kkint32 srcRow = 0; kkint32 srcCol = 0; kkint32 destRow = 0; kkint32 destCol = 0; uchar** srcMatrix = srcRaster.Green (); uchar** destMatrix = destRaster.Green (); kkint32 heightOffset = (srcHeight % multiple) / 2; kkint32 widthOffset = (srcWidth % multiple) / 2; srcRow = -heightOffset; kkint32 r, c; for (destRow = 0; destRow < destHeight; ++destRow) { srcCol = -widthOffset; for (destCol = 0; destCol < destWidth; ++destCol) { kkint32 total = 0; kkint32 srcRowStart = Max (0, srcRow); kkint32 srcRowEnd = Min (srcRow + multiple, srcHeight); kkint32 srcColStart = Max (0, srcCol); kkint32 srcColEnd = Min (srcCol + multiple, srcWidth); kkint32 count = 0; for (r = srcRowStart; r <srcRowEnd; ++r) { for (c = srcColStart; c <srcColEnd; ++c) { total += srcMatrix[r][c]; ++count; } } destMatrix[destRow][destCol] = (uchar)(total / count); srcCol += multiple; } srcRow += multiple; } } /* ReductionByMultiple */
GraphicComp* ImportCmd::TIFF_Image (const char* filename) { GraphicComp* comp = nil; Raster* raster = TIFFRaster::load(filename); if (raster != nil) { raster->ref(); raster->flush(); comp = new RasterComp(new RasterRect(raster), filename); } return comp; }
void MainMongoDB(const char *modelStr, const char *gridFSName, int nSubbasins, const char *host, int port, int dt) { // connect to mongodb mongo conn[1]; gridfs gfs[1]; int status = mongo_connect(conn, host, port); if (MONGO_OK != status) { cout << "can not connect to MongoDB.\n"; exit(-1); } gridfs_init(conn, modelStr, gridFSName, gfs); int subbasinStartID = 1; if (nSubbasins == 0) subbasinStartID = 0; for (int i = subbasinStartID; i <= nSubbasins; i++) { //cout << "subbasin: " << i << endl; //input ostringstream oss; string deltaName, streamLinkName, tName, maskName, landcoverName; oss << i << "_DELTA_S"; deltaName = oss.str(); oss.str(""); oss << i << "_T0_S"; tName = oss.str(); oss.str(""); oss << i << "_MASK"; maskName = oss.str(); oss.str(""); oss << i << "_LANDCOVER"; landcoverName = oss.str(); Raster<int> rsMask; rsMask.ReadFromMongoDB(gfs, maskName.c_str()); Raster<float> rsTime, rsDelta, rsLandcover; rsTime.ReadFromMongoDB(gfs, tName.c_str()); rsDelta.ReadFromMongoDB(gfs, deltaName.c_str()); rsLandcover.ReadFromMongoDB(gfs, landcoverName.c_str()); SubbasinIUHCalculator iuh(dt, rsMask, rsLandcover, rsTime, rsDelta, gfs); iuh.calCell(i); } gridfs_destroy(gfs); mongo_destroy(conn); }
augePixelType RasterMosiacProcessorImpl::GetPixelType(Raster** ppRaster, g_uint count) { Raster* pRaster = NULL; for(g_uint i=0; i<count; i++) { pRaster = ppRaster[i]; if(pRaster!=NULL) { return pRaster->GetPixelType(); } } return augePixelUnknown; }
GraphicComp* ImportCmd::PPM_Image (const char* filename) { GraphicComp* comp = nil; FILE* file = fopen(filename, "r"); boolean compressed; file = CheckCompression(file, filename, compressed); if (file != nil) { char line[1000]; do { fgets(line, 1000, file); } while (strcmp(line, "gsave\n") != 0); fgets(line, 1000, file); // translate fgets(line, 1000, file); // scale fgets(line, 1000, file); // scale fgets(line, 1000, file); // sizes int w, h, d; sscanf(line, "%d %d %d", &w, &h, &d); fgets(line, 1000, file); // [ ... ] fgets(line, 1000, file); // { ... } fgets(line, 1000, file); // false 3 fgets(line, 1000, file); // colorimage Raster* raster = new Raster(w, h); for (int row = h - 1; row >= 0; --row) { for (int column = 0; column < w; ++column) { int red = gethex(file); int green = gethex(file); int blue = gethex(file); raster->poke( column, row, float(red)/0xff, float(green)/0xff, float(blue)/0xff, 1.0 ); } } raster->flush(); comp = new RasterComp(new RasterRect(raster), filename); } if (compressed) { pclose(file); } else { fclose(file); } return comp; }
void raster_test(Pixel *PixelBuffer) { Raster raster; Points *pi1 = new Points; pi1->push_back({10, 10}); pi1->push_back({20, 60}); Points *pi2 = new Points; pi2->push_back({5, 20}); pi2->push_back({60, 25}); point_print(raster.find_intersection(pi1, pi2)); delete pi1; delete pi2; }
int neighborValue(const Raster &raster, int x, int y, bool isTorus) { int numNeighbours = 0; for (int yy = y-1; yy <= y+1; yy++) { for (int xx = x-1; xx <= x+1; xx++) { if (xx == x && yy == y) { continue; // not a neighbour } bool inBounds = raster.inBounds(xx,yy); if (!isTorus && !inBounds) { continue; // i.e. dead } int actualX = xx; int actualY = yy; if (!inBounds) { // transform to torus actualX = (xx + raster.width) % raster.width; actualY = (yy + raster.height) % raster.height; } const int currentCellState = raster.data[raster.index(actualX, actualY)]; if (currentCellState == ALIVE) { numNeighbours++; } } } const int cellState = raster.data[raster.index(x,y)]; // apply rules int newState = DEAD; if (cellState == DEAD && numNeighbours == 3) { newState = ALIVE; } else if (cellState == ALIVE && (numNeighbours == 2 || numNeighbours == 3)) { newState = ALIVE; } return newState; }
int Segment::process(const SegmentParameters ¶ms, Raster &raster) { Size rasterSize=raster.getSize(); if( rasterSize._x!=_pimpl->getDimX() || rasterSize._y!=_pimpl->getDimY() ) throw Exception("Segment: raster size does not match criteria"); return _pimpl->process(params, raster); };
void GrayScaleImagesFVProducer::BinarizeImageByThreshold (uchar lower, uchar upper, const Raster& src, Raster& dest ) { uchar const * srcData = src.GreenArea (); uchar * destData = dest.GreenArea (); kkint32 totPixels = src.TotPixels (); memset (destData, 0, totPixels); kkint32 x = 0; for (x = 0; x < totPixels; ++x) { if ((srcData[x] >= lower) && (srcData[x] < upper)) destData[x] = 255; } } /* BinarizeImageByThreshold */
/* * Copy the object. (Note that this simply copies the member properties * of the class for assigning the object to a new variable. See the * Copy() method for actually copying the raster dataset object to a new * file on disk. */ void Raster::CopyObject(Raster &src) { Init(); m_sFilePath = (char *) malloc(strlen(src.FilePath()) * sizeof(char)+1); std::strcpy(m_sFilePath, src.FilePath()); SetTransform(src.GetTop(), src.GetLeft(), src.GetCellWidth(), src.GetCellHeight()); SetRows(src.GetRows()); SetCols(src.GetCols()); SetNoDataValue(src.GetNoDataValuePtr()); xBlockSize = src.xBlockSize; yBlockSize = src.yBlockSize; }
Raster::Raster(const Raster& raster) { RasterRep* r = new RasterRep; rep_ = r; raster.flush(); RasterRep& rr = *(raster.rep()); r->display_ = rr.display_; r->modified_ = true; r->width_ = rr.width_; r->height_ = rr.height_; r->left_ = rr.left_; r->bottom_ = rr.bottom_; r->right_ = rr.right_; r->top_ = rr.top_; r->pwidth_ = rr.pwidth_; r->pheight_ = rr.pheight_; r->shared_memory_ = false; DisplayRep* dr = r->display_->rep(); XDisplay* dpy = dr->display_; r->pixmap_ = XCreatePixmap( dpy, dr->root_, r->pwidth_, r->pheight_, dr->default_visual_->depth() ); r->gc_ = XCreateGC(dpy, r->pixmap_, 0, nil); XCopyArea( dpy, rr.pixmap_, r->pixmap_, r->gc_, 0, 0, r->pwidth_, r->pheight_, 0, 0 ); #ifdef XSHM init_shared_memory(); #endif if (!r->shared_memory_) { r->image_ = XGetImage( dpy, r->pixmap_, 0, 0, r->pwidth_, r->pheight_, AllPlanes, ZPixmap ); } }
Raster * GfxManager::getRaster(const std::string & filename, bool colorKey) { if (rasters.count(filename)) return rasters[filename]; #if 0 cPNGFile q; std::ifstream file_pal(filename); q. SDL_Surface * surf = loadTexture(filename.c_str(), colorKey); if (surf) { Raster * r = new Raster(); if (r) { r->setSurface(surf); std::cout << "Loaded raster from " << filename << " Original Size: " << surf->w << "x" << surf->h << std::endl; } return r; } #endif return NULL; }
bool RasterMosiacProcessorImpl::ComputeMosiacExtent(GEnvelope& mextent, Raster** ppinRasters, g_uint count) { GEnvelope rect; Raster* pRaster = NULL; for(g_uint i=0; i<count; i++) { pRaster = ppinRasters[i]; rect = pRaster->GetExtent(); if(mextent.IsValid()) { if(rect.IsValid()) { mextent.Union(rect); } } else { mextent = rect; } } return mextent.IsValid(); }
double Get_Skew::histogram( const Raster &raster, double angle) { int i; double sum; double mean; double angle_diff = tan(angle / (180.0 / M_PI)); int diff_y = -static_cast<int>( raster.width() * angle_diff); int min_y = max( 0, diff_y); int max_y = min( static_cast<int>( raster.height()) , raster.height() + diff_y); int num_rows; Fixed dx; int dy; if (raster.height() > m_max_rows) { delete []m_rows; m_rows = new unsigned[ raster.height()]; m_max_rows = raster.height(); } num_rows = (max_y - min_y) / m_sample_skip + 1; if (angle < 0) { dy = -1; } else { dy = +1; } if ((-0.05 < angle) && (angle < 0.05)) { dx = static_cast<int>( raster.width()); } else { dx = dy / (tan( angle / (180.0 / M_PI))); } for (i = 0; i < num_rows; ++i) { m_rows[ i] = cast_ray( raster, min_y + i * m_sample_skip, dx, dy); } sum = 0.0; for (i = 0; i < num_rows; ++i) { sum += m_rows[ i]; } mean = sum / num_rows; sum = 0.0; for (i = 0; i < num_rows; ++i) { sum += sqr( m_rows[ i] - mean); } return sum / num_rows; }
void clip_test(Pixel *PixelBuffer) { Raster raster; Points bounds; bounds.push_back({ 10, 10 }); bounds.push_back({ 10, 100 }); bounds.push_back({ 100, 100 }); bounds.push_back({ 100, 10 }); Points shape; shape.push_back({ 50, 5 }); shape.push_back({ 5, 50 }); shape.push_back({ 50, 115 }); shape.push_back({ 115, 50 }); View view = View(SCREENSIZE, SCREENSIZE, PixelBuffer); Points *p = raster.sutherland_hodgman(&bounds, &shape); Points *r = raster.rasterize(p); view.update_buffer(r); delete r; delete p; }
void simulateInvasion(Raster &raster, float invasionFactor) { if (invasionFactor <= 0) { return; } for (int y = 0; y < raster.height; ++y) { for (int x = 0; x < raster.width; ++x) { float random = static_cast<float>(rand()) / static_cast<float>(RAND_MAX); if (random < invasionFactor) { int index = raster.index(x,y); // flip cell state raster.data[index] = (raster.data[index] + 1) % 2; } } } }
void simulateNextState(Raster &raster, bool isTorus) { const int width = raster.width; const int height = raster.height; int* data = new int[width*height]; for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { int index = raster.index(x,y); data[index] = neighborValue(raster, x, y, isTorus); } } delete[] raster.data; raster.data = data; }
ImageFeaturesPtr PicesFVProducer::ComputeFeatureVector (const Raster& srcImage, const MLClassPtr knownClass, RasterListPtr intermediateImages, float priorReductionFactor, RunLog& runLog ) { ImageFeaturesPtr fv = NULL; RasterSipperListPtr sipperRasterIntermediateImages = NULL; if (intermediateImages) sipperRasterIntermediateImages = new RasterSipperList (false); if (typeid (srcImage) != typeid (MLL::RasterSipper)) { runLog.Level (-1) << endl << "PicesFVProducer::ComputeFeatureVector ***ERROR*** 'srcImage' not a 'RasterSipper' derived class." << endl << " ExampleFileName[" << srcImage.FileName () << "]" << endl << endl; RasterSipperPtr sipperRaster = new RasterSipper (srcImage); fv = new ImageFeatures (*sipperRaster, knownClass, sipperRasterIntermediateImages, runLog); delete sipperRaster; sipperRaster = NULL; } else { MLL::RasterSipperPtr sipperImage = dynamic_cast<MLL::RasterSipperPtr> (&(Raster&)srcImage); fv = new ImageFeatures (*sipperImage, knownClass, sipperRasterIntermediateImages, runLog); } if (sipperRasterIntermediateImages) { for (auto intermdiateIDX: *sipperRasterIntermediateImages) intermediateImages->PushOnBack (intermdiateIDX); sipperRasterIntermediateImages->Owner (false); } delete sipperRasterIntermediateImages; sipperRasterIntermediateImages = NULL; return fv; } /* ComputeFeatureVector */
int Raster<T>::CopyMask(Raster<int> &otherRaster) { m_nRows = otherRaster.GetNumberOfRows(); m_nCols = otherRaster.GetNumberofColumns(); m_xMin = otherRaster.GetXMin(); m_yMax = otherRaster.GetYMax(); m_dx = otherRaster.GetXCellSize(); m_dy = otherRaster.GetYCellSize(); //m_noDataValue = otherRaster.GetNoDataValue(); m_nAll = m_nRows * m_nCols; m_proj = otherRaster.GetProjection(); //allocate memory if(m_data != NULL) CPLFree(m_data); m_data = (T*) CPLMalloc(sizeof(T)*m_nAll); return 0; }
bool Invert::do_invert( const Raster &src, Raster &dest) { try { if (&src != &dest) { dest.redimension( src.width(), src.height(), src.depth(), src.interp()); } size_t words = src.data_words(); Raster_Word * s = src.raster_word(); Raster_Word * d = src.raster_word(); for (size_t i = 0; i < words; ++i) { d[ i] = ~s[ i]; } return true; } catch (...) { return false; } }
unsigned Get_Skew::cast_ray( const Raster &raster, int row, const Fixed &dx, int dy) { unsigned bits = 0; Fixed start = 0; Fixed end = 0; Fixed width = static_cast<int>( raster.width()); int r = row; while (start < width) { end = start + dx; if (end > width) { end = width; } bits += bit_count( raster[ r] , static_cast<int>( start) , static_cast<int>( end)); start = end; r += dy; } return bits; }