Individual *LawnmowerScenario::createIndividual(const QString tree) const { Individual *individual = new Lawnmower(new Environment(gridSize(), gridSize()), maxMoves()); Node *rootNode = treeFactory->buildFromString(tree); individual->setRootNode(rootNode); return individual; }
Individual *LawnmowerScenario::randomIndividual() const { Individual *individual = new Lawnmower(new Environment(gridSize(), gridSize()), maxMoves()); Node *rootNode = treeFactory->build(); individual->setRootNode(rootNode); return individual; }
void ObjectsView::setItemsSize(const QSize &s) { if(model()){ this->model()->setProperty("item_width", QVariant::fromValue(s.width())); this->model()->setProperty("item_height", QVariant::fromValue(s.height())); } this->setGridSize(QSize(s.width()+5, s.height()+5)); this->setMinimumSize(QSize(gridSize().width()+20, gridSize().height()+10)); }
void MonitorProperties::setPointOfView(MonitorProperties::PointOfView pov) { if (pov == m_pointOfView) return; if (m_pointOfView == Undefined) { QVector3D gSize = gridSize(); float units = gridUnits() == MonitorProperties::Meters ? 1000.0 : 304.8; if (gSize.z() == 0) { // convert the grid size first switch (pov) { case TopView: setGridSize(QVector3D(gSize.x(), GRID_DEFAULT_HEIGHT, gSize.y())); break; case RightSideView: case LeftSideView: setGridSize(QVector3D(GRID_DEFAULT_WIDTH, gSize.x(), gSize.x())); break; default: break; } } foreach (quint32 fid, fixtureItemsID()) { QVector3D pos = fixturePosition(fid); QVector3D newPos; switch (pov) { case TopView: { newPos = QVector3D(pos.x(), 1000, pos.y()); } break; case RightSideView: { newPos = QVector3D(0, pos.y(), (gridSize().z() * units) - pos.x()); } break; case LeftSideView: { newPos = QVector3D(0, pos.y(), pos.x()); } break; default: newPos = QVector3D(pos.x(), (gridSize().y() * units) - pos.y(), 1000); break; } setFixturePosition(fid, newPos); }
QModelIndex FolderViewListView::indexAt(const QPoint& point) const { QModelIndex index = QListView::indexAt(point); // NOTE: QListView has a severe design flaw here. It does hit-testing based on the // total bound rect of the item. The width of an item is determined by max(icon_width, text_width). // So if the text label is much wider than the icon, when you click outside the icon but // the point is still within the outer bound rect, the item is still selected. // This results in very poor usability. Let's do precise hit-testing here. // An item is hit only when the point is in the icon or text label. // If the point is in the bound rectangle but outside the icon or text, it should not be selected. if(viewMode() == QListView::IconMode && index.isValid()) { // FIXME: this hack only improves the usability partially. We still need more precise sizeHint handling. // FolderItemDelegate* delegate = static_cast<FolderItemDelegate*>(itemDelegateForColumn(FolderModel::ColumnFileName)); // Q_ASSERT(delegate != NULL); // We use the grid size - (2, 2) as the size of the bounding rectangle of the whole item. // The width of the text label hence is gridSize.width - 2, and the width and height of the icon is from iconSize(). QRect visRect = visualRect(index); // visibal area on the screen QSize itemSize = gridSize(); itemSize.setWidth(itemSize.width() - 2); itemSize.setHeight(itemSize.height() - 2); QSize _iconSize = iconSize(); int textHeight = itemSize.height() - _iconSize.height(); if(point.y() < visRect.bottom() - textHeight) { // the point is in the icon area, not over the text label int iconXMargin = (itemSize.width() - _iconSize.width()) / 2; if(point.x() < (visRect.left() + iconXMargin) || point.x() > (visRect.right() - iconXMargin)) return QModelIndex(); } // qDebug() << "visualRect: " << visRect << "point:" << point; } return index; }
void QGridView::paintEmptyArea( QPainter *p, int cx ,int cy, int cw, int ch) { if ( gridSize().width() >= contentsWidth() && gridSize().height() >= contentsHeight() ) return; // Region of the rect we should draw contentsToViewport( cx, cy, cx, cy ); QRegion reg( QRect( cx, cy, cw, ch ) ); // Subtract the table from it reg = reg.subtract( QRect( contentsToViewport( QPoint( 0, 0 ) ), gridSize() ) ); // And draw the rectangles (transformed as needed) QMemArray<QRect> r = reg.rects(); const QBrush &brush = backgroundBrush(); for ( int i = 0; i < (int)r.count(); ++i) p->fillRect( r[ i ], brush ); }
//-------------------------------------------------------------- void testApp::setup(){ ofBackground(250,250,250); ofSetFrameRate(30); ofSetVerticalSync(true); ofPoint iniPos(0,0,0); //the position is refering to the center of the grid ofPoint gridSize(1500, 1500, 1500); int gridResX = 40; int gridResY = 40; int gridResZ = 40; marchingCubes.init(iniPos, gridSize, gridResX, gridResY, gridResZ); glEnable(GL_DEPTH_TEST); metaBalls.resize(NUM_META_BALLS); for(int i=0; i<metaBalls.size(); i++){ metaBalls[i].init(iniPos); } ofEnableLighting(); ofSetSmoothLighting(true); light.enable(); light.setup(); ofSetLogLevel(OF_LOG_VERBOSE); bSaveModel = false; pointLight.setDiffuseColor( ofColor(0.f, 255.f, 0.f)); // specular color, the highlight/shininess color // pointLight.setSpecularColor( ofColor(255.f, 255.f, 0.f)); pointLight.setPointLight(); float threshold = 0.2; }
void Grid::print_points() const { // check indexing: if (!check()) { print_labels(); return; } for (unsigned int i = 0; i < gridSize(); i++) { // get index set: MultiIndexed::IndexSet is = i2x(i); // get Cartesian point: COORD_CART cp = getPoint(is); cout << "i = " << i << " --> "; for (unsigned int j = 0; j < cp.size(); j++) { cout << "x(" << j << ") = " << cp[j] << " "; } cout << endl; } }
ivec2 ImagePanel::preferredSize (NVGcontext *) const { ivec2 grid = gridSize(); return ivec2 ( grid.x * mThumbSize + (grid.x - 1) * mSpacing + 2 * mMargin, grid.y * mThumbSize + (grid.y - 1) * mSpacing + 2 * mMargin ); }
gpmr::EmitConfiguration IntCountMapper::getEmitConfiguration(gpmr::Chunk * const chunk) const { gpmr::PreLoadedFixedSizeChunk * fsChunk = static_cast<gpmr::PreLoadedFixedSizeChunk * >(chunk); dim3 blockSize(fsChunk->getElementCount(), 1, 1); dim3 gridSize(1, 1, 1); return gpmr::EmitConfiguration::createGridConfiguration(fsChunk->getElementCount() * sizeof(int), fsChunk->getElementCount() * sizeof(int), gridSize, blockSize, 1, sizeof(int), sizeof(int)); }
QSize QWellArray::sizeHint() const { int w = (cellw+margin+1)*nrows; int h = (cellh+margin+1)*ncols; int wh = std::max(w, h); ensurePolished(); return gridSize().boundedTo(QSize(wh, wh)); }
std::vector<int> CravaTrend::GetSizeTrendCubes() const { std::vector<int> gridSize(3); int nI = static_cast<int>(trend_cubes_[0].GetNI()); int nJ = static_cast<int>(trend_cubes_[0].GetNJ()); int nK = static_cast<int>(trend_cubes_[0].GetNK()); gridSize[0] = nI; gridSize[1] = nJ; gridSize[2] = nK; return gridSize; }
void ImagePanel::draw (NVGcontext * ctx) { ivec2 grid = gridSize(); for (size_t i = 0; i < mImages.size(); ++i) { ivec2 p = mPos + ivec2 (mMargin) + ivec2 ((int)i % grid.x, (int)i / grid.x) * (mThumbSize + mSpacing); int imgw, imgh; nvgImageSize (ctx, mImages[i].first, &imgw, &imgh); float iw, ih, ix, iy; if (imgw < imgh) { iw = mThumbSize; ih = iw * (float)imgh / (float)imgw; ix = 0; iy = - (ih - mThumbSize) * 0.5f; } else { ih = mThumbSize; iw = ih * (float)imgw / (float)imgh; ix = - (iw - mThumbSize) * 0.5f; iy = 0; } NVGpaint imgPaint = nvgImagePattern ( ctx, p.x + ix, p.y + iy, iw, ih, 0, mImages[i].first, mMouseIndex == (int)i ? 1.0 : 0.7); nvgBeginPath (ctx); nvgRoundedRect (ctx, p.x, p.y, mThumbSize, mThumbSize, 5); nvgFillPaint (ctx, imgPaint); nvgFill (ctx); NVGpaint shadowPaint = nvgBoxGradient (ctx, p.x - 1, p.y, mThumbSize + 2, mThumbSize + 2, 5, 3, nvgRGBA (0, 0, 0, 128), nvgRGBA (0, 0, 0, 0)); nvgBeginPath (ctx); nvgRect (ctx, p.x - 5, p.y - 5, mThumbSize + 10, mThumbSize + 10); nvgRoundedRect (ctx, p.x, p.y, mThumbSize, mThumbSize, 6); nvgPathWinding (ctx, NVG_HOLE); nvgFillPaint (ctx, shadowPaint); nvgFill (ctx); nvgBeginPath (ctx); nvgRoundedRect (ctx, p.x + 0.5f, p.y + 0.5f, mThumbSize - 1, mThumbSize - 1, 4 - 0.5f); nvgStrokeWidth (ctx, 1.0f); nvgStrokeColor (ctx, nvgRGBA (255, 255, 255, 80)); nvgStroke (ctx); } }
int ImagePanel::indexForPosition (const ivec2 & p) const { vec2 pf (p.x, p.y); vec2 pp = (pf - vec2 (mMargin)) / (float) (mThumbSize + mSpacing); float iconRegion = mThumbSize / (float) (mThumbSize + mSpacing); bool overImage = pp.x - std::floor (pp.x) < iconRegion && pp.y - std::floor (pp.y) < iconRegion; ivec2 pi ((int)pp.x, (int)pp.y); ivec2 gridPos = pi, grid = gridSize(); // FIXME not 100% sure about this so if // things aren't working then check here first bool test1 = (gridPos.x >= 0 && gridPos.y >= 0); bool test2 = (gridPos.x < grid.x && gridPos.y < grid.y); overImage &= test1 && test2; /* overImage &= ((gridPos.array() >= 0).all() && (gridPos.array() < grid.array()).all());*/ return overImage ? (gridPos.x + gridPos.y * grid.x) : -1; }
//-------------------------------------------------------------- void testApp::setup(){ ofBackground(250,250,250); ofSetVerticalSync(true); ofPoint iniPos(0,0,0); //the position is refering to the center of the grid ofPoint gridSize(480, 480, 480); int gridResX = 70; int gridResY = 70; int gridResZ = 70; marchingCubes.init(iniPos, gridSize, gridResX, gridResY, gridResZ); // populate mesh from image with alpha values ofImage img; img.loadImage("linzer.png"); mesh.setMode(OF_PRIMITIVE_POINTS); for(int y = 0; y < img.getHeight(); y+=2) { for(int x = 0; x < img.getWidth(); x+=2) { ofColor cur = img.getColor(x, y); if(cur.a > 0) { // the alpha value encodes depth, let's remap it to a good depth range float z = ofMap(cur.a, 0, 255, -480, 480); cur.a = 255; mesh.addColor(cur); ofVec3f pos(x - img.getWidth() / 2, y - img.getHeight() / 2, z); mesh.addVertex(pos); } } } ofEnableLighting(); light.enable(); light.setup(); bModelRendered = false; bSaveModel = false; bShowCubes = false; ofSetLogLevel(OF_LOG_VERBOSE); }
void CellAutomataAgent::makeAndDistributePartitionTable() { Range indexRange = _pDisplayInfo.getGlobalIndexRange(); Tuple nDivs = indexRange.getSize(); Ptr< Array<int> > xDivs = divideScalarRange(0, _globalSize.at(0), nDivs.at(0)); Ptr< Array<int> > yDivs = divideScalarRange(0, _globalSize.at(1), nDivs.at(1)); PPtr< ManagedArray<DisplayInfoProtocol::NodeInfo> > nodes = _pDisplayInfo.getRemoteInfo(); Ptr< ManagedArray<Partition> > partitions = new ManagedArray<Partition>(); for(int i = nodes->getSize() - 1; i >= 0; i--) { partitions->push(nodeToPartition(xDivs, yDivs, nodes->at(i))); } _local = nodeToPartition(xDivs, yDivs, _pDisplayInfo.getLocalInfo()); partitions->push(_local); ALOG << "Partition Map: " << *partitions << EL; Tuple1D gridSize(partitions->getSize()); Ptr<KGridBasic> grid = new KGridBasic(partition_map_t(), gridSize); Ptr<KRecord> gridRecord = new KRecord(grid.AS(KGrid)); for(RangeIterator i(gridSize); i.hasMore(); i.next()) { partitions->at(i.at(0))->toKRecord(grid->at(i, gridRecord)); } send(R_MATE, OP_PARTITION, grid.AS(KValue)); for(int i = partitions->getSize() - 1; i >= 0; i--) { if(partitions->at(i)->rect.isAdjecentTo(_local->rect)) { _neighbours->push(partitions->at(i)); } } _computeThread->start(); }
//Hand written "host" code, the ideal translation of the former host code in // the CUDA version should be like this int main(void) { int * h_in, *h_out; size_t bytes = NELEMENTS*sizeof(int); h_in = (int*)malloc(bytes); h_out = (int*)malloc(bytes); //initialization for( int i = 0; i < NELEMENTS; i++ ) { h_in[i] = 1; } dim3 blockSize(32,1,1); dim3 gridSize((int)ceil((float)NELEMENTS/blockSize.x), 1, 1); //translated parallel //??? tbb::tick_count t0 = tbb::tick_count::now(); tbb::parallel_for(0, (int) gridSize.z, 1, [=](int z) { tbb::parallel_for(0, (int) gridSize.y, 1, [=](int y) { tbb::parallel_for(0, (int) gridSize.x, 1, [=](int x) { stencil_1d(h_in, h_out, gridSize, blockSize, dim3(x,y,z)); }); }); }); tbb::tick_count t1 = tbb::tick_count::now(); printf("time for action = %g seconds\n", (t1-t0).seconds() ); //std::cout << "work took" << (t1-t0).seconds() << "seconds\n"; //for(int j=0; j < NELEMENTS; j++){ // std::cout << "h_out[" << j << "]= " << h_out[j] << "\n"; //} free(h_in); free(h_out); return 0; }
cuint32_t cgridZ () const { return gridSize ().z (); }
void ListView_Impl::paintDropTarget(QPainter *painter, const QModelIndex& index, int where) { QStyleOptionViewItem option = viewOptions(); QRect rect = this->visualRect(index); QWidget *viewport = this->viewport(); QColor highlight = palette().color(QPalette::HighlightedText); QColor color = option.state & QStyle::State_Selected ? highlight : palette().color(QPalette::Highlight); QPen pen(color); painter->save(); if (!index.isValid()) where = SL_EVENT_DRAG_ON_VIEWPORT; switch (where) { case SL_EVENT_DRAG_BELOW_ITEM: case SL_EVENT_DRAG_ABOVE_ITEM: { if (viewMode() == IconMode) { QSize size = gridSize(); if (size.isEmpty()) size = rect.size(); int x, y, height = size.height(); int cellWidth = size.width() + spacing(); int cellHeight = height + spacing(); x = rect.left() + horizontalOffset(); if (where == SL_EVENT_DRAG_BELOW_ITEM) x += cellWidth; x = ((x / cellWidth) * cellWidth) - horizontalOffset(); y = (((rect.top() + verticalOffset()) / cellHeight) * cellHeight) - verticalOffset(); height = qMax(5, height - 5); painter->setRenderHint(QPainter::Antialiasing); pen.setWidth(3); pen.setColor(highlight); painter->setPen(pen); painter->drawEllipse(QPointF(x, y + height), 3, 3); painter->drawLine(x, y + 5, x, y + height - 3); pen.setWidth(2); pen.setColor(color); painter->setPen(pen); painter->drawEllipse(QPointF(x, y + height), 3, 3); painter->drawLine(x, y + 5, x, y + height - 3); } else { int x, y, width; if (where == SL_EVENT_DRAG_BELOW_ITEM) y = rect.bottom() + 1; else y = rect.top(); x = rect.left(); width = viewport->width() - rect.left() - 10; painter->setRenderHint(QPainter::Antialiasing); pen.setWidth(3); pen.setColor(highlight); painter->setPen(pen); painter->drawEllipse(QPointF(x + width, y), 3, 3); painter->drawLine(x, y, x + width - 3, y); pen.setWidth(2); pen.setColor(color); painter->setPen(pen); painter->drawEllipse(QPointF(x + width, y), 3, 3); painter->drawLine(x, y, x + width - 3, y); } } break; case SL_EVENT_DRAG_ON_ITEM: { option.rect = rect; rect.adjust(1, 1, -1, -1); painter->setRenderHint(QPainter::Antialiasing); int radius = qMin(8, rect.height() / 2); pen.setWidth(3); pen.setColor(highlight); painter->setPen(pen); painter->drawRoundedRect(rect, radius, radius); pen.setWidth(2); if (viewMode() == IconMode) { color = palette().color(QPalette::Inactive, QPalette::Highlight); pen.setColor(color); painter->setPen(pen); painter->setBrush(QBrush(color)); painter->drawRoundedRect(rect, radius, radius); QItemSelectionModel *selection = selectionModel(); if ((selection) && (selection->isSelected(index))) option.state |= QStyle::State_Selected; if (!(model()->flags(index) & Qt::ItemIsEnabled)) option.state &= ~QStyle::State_Enabled; if (option.state & QStyle::State_Enabled) option.palette.setCurrentColorGroup(QPalette::Normal); else option.palette.setCurrentColorGroup(QPalette::Disabled); itemDelegate(index)->paint(painter, option, index); } else { pen.setColor(color); painter->setPen(pen); painter->drawRoundedRect(rect, radius, radius); } } break; case SL_EVENT_DRAG_ON_VIEWPORT: { rect = viewport->rect(); rect.adjust(0, 0, -1, -1); painter->setRenderHint(QPainter::Antialiasing, false); pen.setWidth(5); pen.setColor(highlight); painter->setPen(pen); painter->drawRect(rect); pen.setWidth(3); pen.setColor(color); painter->setPen(pen); painter->drawRect(rect); } break; } painter->restore(); }
vector<IO::OFILE::Data> Grid::getOData(const string & type) const { vector<IO::OFILE::Data> out; //////////////////////////////////////////////////////////// // // Text file output: // if (type.compare(IO::OFILE::TYPE::TXT) == 0) { // add a piece of data: points IO::OFILE::Data dat; // set pre and post fields: dat.type = type; dat.origin = gridName; // Output Cartesian points: if (flag_output_cart) { dat.name = "grid_points_cartesian"; dat.pre_data = "// " + gridName + ": " + String(gSize) + " points in Cartesian space (" + String(getN()) + ")\n"; for (unsigned int g = 0; g < gridSize(); ++g) { // pick a coordinate: const MultiIndexed::IndexSet coord = g2x(g); // get Cartesian coordinate: COORD_GRID x = getPoint(coord); // write: dat.data += String(x) + " "; } } // grid point output: else { dat.name = "grid_points"; dat.pre_data = "// " + gridName + ": " + String(indexSize()) + " points in grid space (" + String(getN()) + ")\n"; for (unsigned int i = 0; i < indexSize(); i++) { // pick a coordinate: MultiIndexed::IndexSet coord = i2x(i); // get Cartesian coordinate: COORD_GRID x = getGridPoint(coord); // write: dat.data += String(x) + " "; } } // write points: dat.data += "\n"; out.push_back(dat); } //////////////////////////////////////////////////////////// // // VTK ascii file output: // else if (type.compare(IO::OFILE::TYPE::VTK_ASCII) == 0) { // add a piece of data: points IO::OFILE::Data dat; // set pre and post fields: dat.type = type; dat.origin = gridName; // Output Cartesian points: if (flag_output_cart) { // meta data for grid points: vector<int> dims = getN(); dims.resize(3, 1); dat.name = "grid_points_cartesian"; dat.pre_data = String("DATASET UNSTRUCTURED_GRID\n") // + "DIMENSIONS " + IO::vi2s(dims) + "\n" + "POINTS " + String(gridSize()) + " \n"; for (unsigned int g = 0; g < gridSize(); g++) { // pick a coordinate: MultiIndexed::IndexSet coord = g2x(g); // get Cartesian coordinate: COORD_GRID x = getPoint(coord); // vtk expects 3 dimensions: x.resize(3, 0); // write: dat.data += String(x) + " "; } } // grid point output: else { // meta data for grid points: vector<int> dims = getN(); dims.resize(3, 1); dat.name = "grid_points"; dat.pre_data = String("DATASET STRUCTURED_GRID\n") + "DIMENSIONS " + String(dims) + "\n" + "POINTS " + String(indexSize()) + " \n"; for (unsigned int i = 0; i < indexSize(); i++) { // pick a coordinate: MultiIndexed::IndexSet coord = i2x(i); // get Cartesian coordinate: COORD_GRID x = getPoint(coord); // vtk expects 3 dimensions: x.resize(3, 0); // write: dat.data += String(x) + " "; } } // write points: dat.data += "\n"; out.push_back(dat); // add new piece of data: cells dat = IO::OFILE::Data(); // set pre and post fields: dat.type = type; dat.origin = gridName; dat.pre_data = "CELLS " + String(cells()) + " "; dat.data = ""; // Output in Cartesian space: if (flag_output_cart) { dat.name = "grid_cells_cartesian"; // count data output: int dcounter = 0; // cell output: for(int i = 0; i < cells(); i++) { // get cell: MultiIndexed::IndexCell cell = getIndexCell(i); // grid filter: for(unsigned j = 0; j < cell.size(); j++) cell[j] = filter_i2g(cell[j]); reduceDup_v(cell); // write cell: dat.data += String(cell.size()); dcounter++; for(unsigned j = 0; j < cell.size(); j++){ cout<<String(cell[j])<<" -> "<<String(x2g(cell[j]))<<endl; dat.data += " " + String(x2g(cell[j])); dcounter++; } cout<<endl; dat.data += "\n"; } dat.pre_data += String(dcounter) + "\n"; } dat.data += "\n"; out.push_back(dat); } return out; }
bool ossimH5GridModel::setGridNodes( H5::DataSet* latDataSet, H5::DataSet* lonDataSet, const ossimIrect& validRect ) { bool status = false; if ( latDataSet && lonDataSet ) { m_crossesDateline = ossim_hdf5::crossesDateline( *lonDataSet, validRect ); if ( m_crossesDateline ) { theLonGrid.setDomainType(ossimDblGrid::WRAP_360); } else { theLonGrid.setDomainType(ossimDblGrid::WRAP_180); } // Get dataspace of the dataset. H5::DataSpace latDataSpace = latDataSet->getSpace(); H5::DataSpace lonDataSpace = lonDataSet->getSpace(); const ossim_int32 LAT_DIM_COUNT = latDataSpace.getSimpleExtentNdims(); const ossim_int32 LON_DIM_COUNT = lonDataSpace.getSimpleExtentNdims(); // Number of dimensions of the input dataspace: if ( ( LAT_DIM_COUNT == 2 ) && ( LON_DIM_COUNT == 2 ) ) { const ossim_uint32 ROWS = validRect.height(); const ossim_uint32 COLS = validRect.width(); const ossim_uint32 GRID_SIZE = 4; // Only grab every 4th value. //--- // Get the extents: // dimsOut[0] is height, dimsOut[1] is width: //--- std::vector<hsize_t> latDimsOut(LAT_DIM_COUNT); latDataSpace.getSimpleExtentDims( &latDimsOut.front(), 0 ); std::vector<hsize_t> lonDimsOut(LON_DIM_COUNT); lonDataSpace.getSimpleExtentDims( &lonDimsOut.front(), 0 ); // Verify valid rect within our bounds: if ( (ROWS <= latDimsOut[0] ) && (ROWS <= lonDimsOut[0] ) && (COLS <= latDimsOut[1] ) && (COLS <= lonDimsOut[1] ) ) { //---- // Initialize the ossimDblGrids: //--- ossimDpt dspacing (GRID_SIZE, GRID_SIZE); ossim_uint32 gridRows = ROWS / GRID_SIZE + 1; ossim_uint32 gridCols = COLS / GRID_SIZE + 1; // Round up if size doesn't fall on end pixel. if ( ROWS % GRID_SIZE) ++gridRows; if ( COLS % GRID_SIZE) ++gridCols; ossimIpt gridSize (gridCols, gridRows); // The grid as used in base class, has UV-space always at 0,0 origin ossimDpt gridOrigin(0.0,0.0); const ossim_float64 NULL_VALUE = -999.0; theLatGrid.setNullValue(ossim::nan()); theLonGrid.setNullValue(ossim::nan()); theLatGrid.initialize(gridSize, gridOrigin, dspacing); theLonGrid.initialize(gridSize, gridOrigin, dspacing); std::vector<hsize_t> inputCount(LAT_DIM_COUNT); std::vector<hsize_t> inputOffset(LAT_DIM_COUNT); inputOffset[0] = 0; // row is set below. inputOffset[1] = validRect.ul().x; // col inputCount[0] = 1; // row inputCount[1] = (hsize_t)COLS; // col // Output dataspace dimensions. Reading a line at a time. const ossim_int32 OUT_DIM_COUNT = 3; std::vector<hsize_t> outputCount(OUT_DIM_COUNT); outputCount[0] = 1; // band outputCount[1] = 1; // row outputCount[2] = COLS; // col // Output dataspace offset. std::vector<hsize_t> outputOffset(OUT_DIM_COUNT); outputOffset[0] = 0; outputOffset[1] = 0; outputOffset[2] = 0; ossimScalarType scalar = ossim_hdf5::getScalarType( latDataSet ); if ( scalar == OSSIM_FLOAT32 ) { // Set the return status to true if we get here... status = true; // See if we need to swap bytes: ossimEndian* endian = 0; if ( ( ossim::byteOrder() != ossim_hdf5::getByteOrder( latDataSet ) ) ) { endian = new ossimEndian(); } // Native type: H5::DataType latDataType = latDataSet->getDataType(); H5::DataType lonDataType = lonDataSet->getDataType(); // Output dataspace always the same, width of one line. H5::DataSpace bufferDataSpace( OUT_DIM_COUNT, &outputCount.front()); bufferDataSpace.selectHyperslab( H5S_SELECT_SET, &outputCount.front(), &outputOffset.front() ); // Arrays to hold a single line of latitude longitude values. vector<ossim_float32> latValue(COLS); vector<ossim_float32> lonValue(COLS); hsize_t row = 0; // Line loop: for ( ossim_uint32 y = 0; y < gridRows; ++y ) { // row = line in image space row = y*GRID_SIZE; if ( row < ROWS ) { inputOffset[0] = row + validRect.ul().y; latDataSpace.selectHyperslab( H5S_SELECT_SET, &inputCount.front(), &inputOffset.front() ); lonDataSpace.selectHyperslab( H5S_SELECT_SET, &inputCount.front(), &inputOffset.front() ); // Read data from file into the buffer. latDataSet->read( &(latValue.front()), latDataType, bufferDataSpace, latDataSpace ); lonDataSet->read( &(lonValue.front()), lonDataType, bufferDataSpace, lonDataSpace ); if ( endian ) { // If the endian pointer is initialized(not zero) swap the bytes. endian->swap( &(latValue.front()), COLS ); endian->swap( &(lonValue.front()), COLS ); } // Sample loop: hsize_t col = 0; for ( ossim_uint32 x = 0; x < gridCols; ++x ) { ossim_float32 lat = ossim::nan(); ossim_float32 lon = ossim::nan(); // col = sample in image space col = x*GRID_SIZE; if ( col < COLS ) { if ( (latValue[col] > NULL_VALUE)&&(lonValue[col] > NULL_VALUE) ) { lat = latValue[col]; lon = lonValue[col]; if ( m_crossesDateline ) { if ( lon < 0.0 ) lon += 360; } } else // Nulls in grid! { std::string errMsg = "ossimH5GridModel::setGridNodes encountered nans!"; throw ossimException(errMsg); } } else // Last column is outside of image bounds. { // Get the last two latitude values: ossim_float32 lat1 = theLatGrid.getNode( x-2, y ); ossim_float32 lat2 = theLatGrid.getNode( x-1, y ); // Get the last two longitude values ossim_float32 lon1 = theLonGrid.getNode( x-2, y ); ossim_float32 lon2 = theLonGrid.getNode( x-1, y ); if ( ( lat1 > NULL_VALUE ) && ( lat2 > NULL_VALUE ) ) { // Delta between last two latitude grid values. ossim_float32 latSpacing = lat2 - lat1; // Compute: lat = lat2 + latSpacing; } else // Nulls in grid! { std::string errMsg = "ossimH5GridModel::setGridNodes encountered nans!"; throw ossimException(errMsg); } if ( ( lon1 > NULL_VALUE ) && ( lon2 > NULL_VALUE ) ) { // Delta between last two longitude values. ossim_float32 lonSpacing = lon2 - lon1; // Compute: lon = lon2 + lonSpacing; // Check for wrap: if ( !m_crossesDateline && ( lon > 180 ) ) { lon -= 360.0; } } else // Nulls in grid! { std::string errMsg = "ossimH5GridModel::setGridNodes encountered nans!"; throw ossimException(errMsg); } #if 0 /* Please leave for debug. (drb) */ cout << "lat1: " << lat1 << " lat2 " << lat2 << " lon1 " << lon1 << " lon2 " << lon2 << "\n"; #endif } // Assign the latitude and longitude. theLatGrid.setNode( x, y, lat ); theLonGrid.setNode( x, y, lon ); #if 0 /* Please leave for debug. (drb) */ cout << "x,y,col,row,lat,lon:" << x << "," << y << "," << col << "," << row << "," << theLatGrid.getNode(x, y) << "," << theLonGrid.getNode( x, y) << "\n"; #endif } // End sample loop. } else // Row is outside of image bounds: { // Sample loop: for ( ossim_uint32 x = 0; x < gridCols; ++x ) { ossim_float32 lat = ossim::nan(); ossim_float32 lon = ossim::nan(); ossim_float32 lat1 = theLatGrid.getNode( x, y-2 ); ossim_float32 lat2 = theLatGrid.getNode( x, y-1 ); ossim_float32 lon1 = theLonGrid.getNode( x, y-2 ); ossim_float32 lon2 = theLonGrid.getNode( x, y-1 ); if ( ( lon1 > NULL_VALUE ) && ( lon2 > NULL_VALUE ) ) { // Delta between last two longitude values. ossim_float32 lonSpacing = lon2 - lon1; // Compute: lon = lon2 + lonSpacing; // Check for wrap: if ( !m_crossesDateline && ( lon > 180 ) ) { lon -= 360.0; } } else // Nulls in grid! { std::string errMsg = "ossimH5GridModel::setGridNodes encountered nans!"; throw ossimException(errMsg); } if ( ( lat1 > NULL_VALUE ) && ( lat2 > NULL_VALUE ) ) { // Delta between last two latitude values. ossim_float32 latSpacing = lat2 - lat1; lat = lat2 + latSpacing; } else // Nulls in grid! { std::string errMsg = "ossimH5GridModel::setGridNodes encountered nans!"; throw ossimException(errMsg); } #if 0 /* Please leave for debug. (drb) */ hsize_t col = x*GRID_SIZE; // Sample in image space cout << "lat1: " << lat1 << " lat2 " << lat2 << " lon1 " << lon1 << " lon2 " << lon2 << "\nx,y,col,row,lat,lon:" << x << "," << y << "," << col << "," << row << "," << lat << "," << lon << "\n"; #endif // Assign the latitude:: theLatGrid.setNode( x, y, lat ); // Assign the longitude. theLonGrid.setNode( x, y, lon ); } // End sample loop. } // Matches if ( row < imageRows ){...}else{ } // End line loop. latDataSpace.close(); lonDataSpace.close(); if ( status ) { theSeedFunction = ossim_hdf5::getBilinearProjection( *latDataSet,*lonDataSet, validRect ); // Bileaner projection to handle ossimDrect imageRect(validRect); initializeModelParams(imageRect); // debugDump(); } if ( endian ) { delete endian; endian = 0; } } // Matches: if ( scalar == OSSIM_FLOAT32 ) } // Matches: if ( (latDimsOut[0] == imageRows) ... } // Matches: if ( ( LAT_DIM_COUNT == 2 ) ... } // Matches: if ( latDataSet && lonDataSet return status; } // End: bool ossimH5GridModel::setGridNodes( H5::DataSet* latDataSet, ... )
void Grid::identifyPoints() { // clear lists: filterMap_i2g.clear(); filterMap_g2i.clear(); // prepare: MultiIndexed::IndexSetSet identical; vector<COORD_CART> checked; vector<int> checked_i; vector<COORD_CART> doubles; int duplicates = 0; int actLabel = 0; // loop: for (unsigned int i = 0; i < indexSize(); i++) { // current index set: MultiIndexed::IndexSet is = i2x(i); // get Cartesian point: COORD_CART cp = getPoint(is); // check if this has been found before: vector<COORD_CART>::iterator bef = find(checked.begin(), checked.end(), cp); // yes, this is a duplicate: if (bef != checked.end()) { // the old label: int i_old = 0; // search the original: vector<COORD_CART>::iterator found = find(doubles.begin(), doubles.end(), cp); // yes, found it: if (found != doubles.end()) { // get position: int pos = found - doubles.begin(); i_old = (identical[pos])[0]; // write: identical[pos].push_back(i); // tell: cout << gridName << ": Found duplicate. Identify (" << String(is) << ") with (" << String(i2x(i_old)) << ")." << endl; // this reduces the grid size, so count: duplicates++; } // no, it's new: else { // add to lists: doubles.push_back(cp); i_old = bef - checked.begin(); MultiIndexed::IndexSet newpair(2); newpair[0] = i_old; newpair[1] = i; identical.push_back(newpair); // tell: cout << gridName << ": Found duplicate. Identify (" << String(is) << ") with (" << String(i2x( (identical.back())[0])) << ")" << endl; // this reduces the grid size, so count: duplicates++; } // write original label to filter: filterMap_i2g.push_back(i_old); } // no, this is not a duplicate: else { // give label: filterMap_i2g.push_back(actLabel); filterMap_g2i.push_back(i); actLabel++; // mark as checked: checked.push_back(cp); checked_i.push_back(i); } } // reduce grid size: gSize -= duplicates; cout<<"i2gMap: " << endl; cout<<String(filterMap_i2g)<<endl; cout<<"g2iMap: " << endl; cout<<String(filterMap_g2i)<<endl; cout << gridName << ": Index size = " << indexSize() << ", grid size = " << gridSize() << endl; }
void FakeMDEventData::addFakeRegularData( const std::vector<double> ¶ms, typename MDEventWorkspace<MDE, nd>::sptr ws) { // the parameters for regular distribution of events over the box std::vector<double> startPoint(nd), delta(nd); std::vector<size_t> indexMax(nd); size_t gridSize(0); // bool RandomizeSignal = getProperty("RandomizeSignal"); size_t num = size_t(params[0]); if (num == 0) throw std::invalid_argument( " number of distributed events can not be equal to 0"); Progress prog(this, 0.0, 1.0, 100); size_t progIncrement = num / 100; if (progIncrement == 0) progIncrement = 1; // Inserter to help choose the correct event type auto eventHelper = MDEvents::MDEventInserter<typename MDEventWorkspace<MDE, nd>::sptr>(ws); gridSize = 1; for (size_t d = 0; d < nd; ++d) { double min = ws->getDimension(d)->getMinimum(); double max = ws->getDimension(d)->getMaximum(); double shift = params[d * 2 + 1]; double step = params[d * 2 + 2]; if (shift < 0) shift = 0; if (shift >= step) shift = step * (1 - FLT_EPSILON); startPoint[d] = min + shift; if ((startPoint[d] < min) || (startPoint[d] >= max)) throw std::invalid_argument("RegularData: starting point must be within " "the box for all dimensions."); if (step <= 0) throw(std::invalid_argument( "Step of the regular grid is less or equal to 0")); indexMax[d] = size_t((max - min) / step); if (indexMax[d] == 0) indexMax[d] = 1; // deal with round-off errors while ((startPoint[d] + double(indexMax[d] - 1) * step) >= max) step *= (1 - FLT_EPSILON); delta[d] = step; gridSize *= indexMax[d]; } // Create all the requested events std::vector<size_t> indexes; size_t cellCount(0); for (size_t i = 0; i < num; ++i) { coord_t centers[nd]; Kernel::Utils::getIndicesFromLinearIndex(cellCount, indexMax, indexes); ++cellCount; if (cellCount >= gridSize) cellCount = 0; for (size_t d = 0; d < nd; d++) { centers[d] = coord_t(startPoint[d] + delta[d] * double(indexes[d])); } // Default or randomized error/signal float signal = 1.0; float errorSquared = 1.0; // if (RandomizeSignal) //{ // signal = float(0.5 + genUnit()); // errorSquared = float(0.5 + genUnit()); //} // Create and add the event. eventHelper.insertMDEvent(signal, errorSquared, 1, pickDetectorID(), centers); // 1 = run number // Progress report if ((i % progIncrement) == 0) prog.report(); } }
std::shared_ptr<ResultSet> Executor::execute(const Planner::RootPlan* root_plan, const Catalog_Namespace::SessionInfo& session, const bool hoist_literals, const ExecutorDeviceType device_type, const ExecutorOptLevel opt_level, const bool allow_multifrag, const bool allow_loop_joins, RenderInfo* render_info) { catalog_ = &root_plan->get_catalog(); const auto stmt_type = root_plan->get_stmt_type(); // capture the lock acquistion time auto clock_begin = timer_start(); std::lock_guard<std::mutex> lock(execute_mutex_); if (g_enable_dynamic_watchdog) { resetInterrupt(); } ScopeGuard restore_metainfo_cache = [this] { clearMetaInfoCache(); }; int64_t queue_time_ms = timer_stop(clock_begin); ScopeGuard row_set_holder = [this] { row_set_mem_owner_ = nullptr; }; switch (stmt_type) { case kSELECT: { int32_t error_code{0}; size_t max_groups_buffer_entry_guess{16384}; std::unique_ptr<RenderInfo> render_info_ptr; if (root_plan->get_plan_dest() == Planner::RootPlan::kRENDER) { if (device_type != ExecutorDeviceType::GPU) { throw std::runtime_error("Backend rendering is only supported on GPU"); } if (!render_manager_) { throw std::runtime_error("This build doesn't support backend rendering"); } CHECK(render_info); if (!render_info->render_allocator_map_ptr) { // make backwards compatible, can be removed when MapDHandler::render(...) // in MapDServer.cpp is removed render_info->render_allocator_map_ptr.reset( new RenderAllocatorMap(catalog_->get_dataMgr().cudaMgr_, render_manager_, blockSize(), gridSize())); } } auto rows = executeSelectPlan( root_plan->get_plan(), root_plan->get_limit(), root_plan->get_offset(), hoist_literals, device_type, opt_level, root_plan->get_catalog(), max_groups_buffer_entry_guess, &error_code, nullptr, allow_multifrag, root_plan->get_plan_dest() == Planner::RootPlan::kEXPLAIN, allow_loop_joins, render_info && render_info->do_render ? render_info->render_allocator_map_ptr.get() : nullptr); if (error_code == ERR_OVERFLOW_OR_UNDERFLOW) { throw std::runtime_error("Overflow or underflow"); } if (error_code == ERR_DIV_BY_ZERO) { throw std::runtime_error("Division by zero"); } if (error_code == ERR_UNSUPPORTED_SELF_JOIN) { throw std::runtime_error("Self joins not supported yet"); } if (error_code == ERR_OUT_OF_TIME) { if (!interrupted_) throw std::runtime_error("Query execution has exceeded the time limit"); error_code = ERR_INTERRUPTED; } if (error_code == ERR_INTERRUPTED) { throw std::runtime_error("Query execution has been interrupted"); } if (error_code == ERR_OUT_OF_CPU_MEM) { throw std::runtime_error("Not enough host memory to execute the query"); } if (error_code == ERR_OUT_OF_GPU_MEM) { rows = executeSelectPlan(root_plan->get_plan(), root_plan->get_limit(), root_plan->get_offset(), hoist_literals, device_type, opt_level, root_plan->get_catalog(), max_groups_buffer_entry_guess, &error_code, nullptr, false, false, allow_loop_joins, nullptr); } if (error_code) { max_groups_buffer_entry_guess = 0; while (true) { rows = executeSelectPlan(root_plan->get_plan(), root_plan->get_limit(), root_plan->get_offset(), hoist_literals, ExecutorDeviceType::CPU, opt_level, root_plan->get_catalog(), max_groups_buffer_entry_guess, &error_code, nullptr, false, false, allow_loop_joins, nullptr); CHECK(rows); if (!error_code) { rows->setQueueTime(queue_time_ms); return rows; } // Even the conservative guess failed; it should only happen when we group // by a huge cardinality array. Maybe we should throw an exception instead? // Such a heavy query is entirely capable of exhausting all the host memory. CHECK(max_groups_buffer_entry_guess); max_groups_buffer_entry_guess *= 2; } } CHECK(rows); rows->setQueueTime(queue_time_ms); return rows; } case kINSERT: { if (root_plan->get_plan_dest() == Planner::RootPlan::kEXPLAIN) { auto explanation_rs = std::make_shared<ResultSet>("No explanation available."); explanation_rs->setQueueTime(queue_time_ms); return explanation_rs; } Catalog_Namespace::Catalog& cat = session.get_catalog(); Catalog_Namespace::SysCatalog& sys_cat = static_cast<Catalog_Namespace::SysCatalog&>(cat); auto user_metadata = session.get_currentUser(); const int table_id = root_plan->get_result_table_id(); auto td = cat.getMetadataForTable(table_id); DBObject dbObject(td->tableName, TableDBObjectType); std::vector<bool> privs{false, true, false, false}; // INSERT sys_cat.populateDBObjectKey(dbObject, cat); dbObject.setPrivileges(privs); std::vector<DBObject> privObjects; privObjects.push_back(dbObject); if (cat.isAccessPrivCheckEnabled() && !sys_cat.checkPrivileges(user_metadata, privObjects)) { throw std::runtime_error("Violation of access privileges: user " + user_metadata.userName + " has no insert privileges for table " + td->tableName + "."); break; } executeSimpleInsert(root_plan); auto empty_rs = std::make_shared<ResultSet>( std::vector<TargetInfo>{}, ExecutorDeviceType::CPU, QueryMemoryDescriptor{}, nullptr, this); empty_rs->setQueueTime(queue_time_ms); return empty_rs; } default: CHECK(false); } CHECK(false); return nullptr; }
int main(int argc,char* argv[]) { /* Set up the volumetric grid: */ Box gridBox=Box(Point(-32.0,-64.0,16.0),Point(32.0,0.0,80.0)); Index gridSize(256,256,256); Grid grid(gridSize); /* Initialize the grid: */ for(Grid::iterator gIt=grid.begin();gIt!=grid.end();++gIt) *gIt=Voxel(255); /* Carve away the n-th facade from each depth stream file listed on the command line: */ unsigned int facadeIndex=atoi(argv[1]); for(int depthFileIndex=2;depthFileIndex<argc;++depthFileIndex) { try { /* Open the depth file: */ IO::AutoFile depthFile(IO::openFile(argv[depthFileIndex])); depthFile->setEndianness(IO::File::LittleEndian); /* Read the facade projection matrix and the projector transformation: */ Projection depthTransform; depthFile->read<double>(depthTransform.getMatrix().getEntries(),4*4); OGTransform projectorTransform=Misc::Marshaller<OGTransform>::read(*depthFile); /* Calculate the joint projective transformation from 3D world space into depth image space: */ Projection proj=Geometry::invert(Projection(projectorTransform)*depthTransform); /* Create a depth frame reader: */ DepthFrameReader depthFrameReader(*depthFile); /* Read the n-th facade: */ FrameBuffer frame; for(unsigned int i=0;i<facadeIndex;++i) frame=depthFrameReader.readNextFrame(); /* Run a sequence of morphological open and close operators on the frame to fill holes: */ #if 1 for(int i=0;i<8;++i) frame=open(frame); #endif #if 1 for(int i=0;i<8;++i) frame=close(frame); #endif /* Carve the facade out of the grid: */ std::cout<<"Processing depth file "<<argv[depthFileIndex]<<std::flush; double fmax[2]; for(int i=0;i<2;++i) fmax[i]=double(frame.getSize(i)); unsigned short* frameBuffer=static_cast<unsigned short*>(frame.getBuffer()); Size cellSize; for(int i=0;i<3;++i) cellSize[i]=(gridBox.max[i]-gridBox.min[i])/double(gridSize[i]); Index index; Point gridp; gridp[0]=gridBox.min[0]+0.5*cellSize[0]; for(index[0]=0;index[0]<gridSize[0];++index[0],gridp[0]+=cellSize[0]) { gridp[1]=gridBox.min[1]+0.5*cellSize[1]; for(index[1]=0;index[1]<gridSize[1];++index[1],gridp[1]+=cellSize[1]) { gridp[2]=gridBox.min[2]+0.5*cellSize[2]; for(index[2]=0;index[2]<gridSize[2];++index[2],gridp[2]+=cellSize[2]) { /* Project the grid point into the depth frame: */ Point fp=proj.transform(gridp); /* Check if the projected grid point is inside the depth frame: */ if(fp[0]>=0.0&&fp[0]<fmax[0]&&fp[1]>=0.0&&fp[1]<fmax[1]) { /* Check if the grid point is outside the facade: */ int x=int(fp[0]); int y=int(fp[1]); unsigned short depth=frameBuffer[y*frame.getSize(0)+x]; if(fp[2]<double(depth)) grid(index)=Voxel(0); } else grid(index)=Voxel(0); } } std::cout<<'.'<<std::flush; } std::cout<<"done"<<std::endl; } catch(std::runtime_error err) { std::cerr<<"Ignoring depth file "<<argv[depthFileIndex]<<" due to exception "<<err.what()<<std::endl; } catch(...) { std::cerr<<"Ignoring depth file "<<argv[depthFileIndex]<<" due to spurious exception"<<std::endl; } } /* Save the result grid to a volume file: */ IO::AutoFile volFile(IO::openFile("SpaceCarverOut.vol",IO::File::WriteOnly)); volFile->setEndianness(IO::File::BigEndian); for(int i=0;i<3;++i) volFile->write<int>(int(gridSize[i])); volFile->write<int>(0); for(int i=0;i<3;++i) volFile->write<float>((gridBox.max[i]-gridBox.min[i])*double(gridSize[i]-1)/double(gridSize[i])); volFile->write<Voxel>(grid.getArray(),grid.getNumElements()); return 0; }
cuint32_t cgridY () const { return gridSize ().y (); }
void ossimH5GridModel::initializeModelParams(ossimIrect imageBounds) { theLatGrid.enableExtrapolation(); theLonGrid.enableExtrapolation(); theHeightEnabledFlag = false; // NOTE: it is assumed that the grid size and spacing is the same for ALL grids: ossimIpt gridSize (theLatGrid.size()); ossimDpt spacing (theLatGrid.spacing()); ossimDpt v[4]; v[0].lat = theLatGrid.getNode(0,0); v[0].lon = theLonGrid.getNode(0,0); v[1].lat = theLatGrid.getNode(gridSize.x-1, 0); v[1].lon = theLonGrid.getNode(gridSize.x-1, 0); v[2].lat = theLatGrid.getNode(gridSize.x-1, gridSize.y-1); v[2].lon = theLonGrid.getNode(gridSize.x-1, gridSize.y-1); v[3].lat = theLatGrid.getNode(0, gridSize.y-1); v[3].lon = theLonGrid.getNode(0, gridSize.y-1); if ( m_crossesDateline ) { // Longitude values between 0 and 360. m_boundGndPolygon = ossimPolygon(4, v); } // Guaranty longitude values are -180 to 180 for (int i=0; i<4; ++i) { if (v[i].lon > 180.0) v[i].lon -= 360.0; } theBoundGndPolygon = ossimPolygon(4, v); if ( !m_crossesDateline ) { // Longitude values between -180 and 180. m_boundGndPolygon = theBoundGndPolygon; } theImageSize = ossimDpt(imageBounds.width(), imageBounds.height()); theRefImgPt = imageBounds.midPoint(); theRefGndPt.lat = theLatGrid(theRefImgPt); theRefGndPt.lon = theLonGrid(theRefImgPt); ossimDpt ref_ip_dx (theRefImgPt.x+1.0, theRefImgPt.y ); ossimDpt ref_ip_dy (theRefImgPt.x , theRefImgPt.y+1.0); ossimGpt ref_gp_dx (theLatGrid(ref_ip_dx), theLonGrid(ref_ip_dx)); ossimGpt ref_gp_dy (theLatGrid(ref_ip_dy), theLonGrid(ref_ip_dy)); theGSD.x = theRefGndPt.distanceTo(ref_gp_dx); theGSD.y = theRefGndPt.distanceTo(ref_gp_dy); theMeanGSD = (theGSD.line + theGSD.samp)/2.0; theImageClipRect = imageBounds; // Image is clipped to valid rect so no sub image offset. theSubImageOffset = ossimDpt(0.0, 0.0); //imageBounds.ul(); theRefGndPt.limitLonTo180(); // debugDump(); } // End: initializeModelParams
Visualization::Abstract::DataSet* MultiVolFile::load(const std::vector<std::string>& args,Comm::MulticastPipe* pipe) const { /* Create the result data set: */ Misc::SelfDestructPointer<DataSet> result(new DataSet); DS& dataSet=result->getDs(); /* Initialize the result data set's data value: */ DataValue& dataValue=result->getDataValue(); dataValue.initialize(&dataSet,0); /* Parse the module arguments: */ DS::Index gridSize(0); DS::Point gridOrigin=DS::Point::origin; DS::Size gridCellSize=DS::Size(0); bool gridInitialized=false; for(size_t argc=0;argc<args.size();argc+=2) { /* Open the vol file: */ Misc::File volFile(args[argc+1].c_str(),"rb",Misc::File::LittleEndian); /* Read the vol file header: */ DS::Index volGridSize; for(int i=0;i<3;++i) volGridSize[i]=volFile.read<int>(); DS::Point volGridOrigin; for(int i=0;i<3;++i) volGridOrigin[i]=Scalar(volFile.read<float>()); DS::Size volGridCellSize; for(int i=0;i<3;++i) volGridCellSize[i]=Scalar(volFile.read<float>()); bool volOk=true; if(gridInitialized) { /* Check the vol file for consistency: */ if(volGridSize!=gridSize||volGridOrigin!=gridOrigin||volGridCellSize!=gridCellSize) { std::cout<<"Vol file "<<args[argc+1]<<" does not match data set layout; skipping"<<std::endl; volOk=false; } } else { /* Initialize the result data set: */ gridSize=volGridSize; gridOrigin=volGridOrigin; gridCellSize=volGridCellSize; dataSet.setData(gridSize,gridCellSize,0); gridInitialized=true; } if(volOk) { /* Determine the vol file's value type: */ unsigned int volTypeSize=volFile.read<unsigned int>(); if(volTypeSize==1||volTypeSize==2||volTypeSize==4||volTypeSize==8) { /* Add a new slice to the data set: */ int newSliceIndex=dataSet.addSlice(); /* Add a new scalar variable to the data value: */ dataValue.addScalarVariable(args[argc].c_str()); /* Read the vol file: */ if(volTypeSize==1) readVolFile<unsigned char>(volFile,dataSet,newSliceIndex); else if(volTypeSize==2) readVolFile<signed short int>(volFile,dataSet,newSliceIndex); else if(volTypeSize==4) readVolFile<float>(volFile,dataSet,newSliceIndex); else readVolFile<double>(volFile,dataSet,newSliceIndex); } else std::cout<<"Vol file "<<args[argc+1]<<" has unknown data type; skipping"<<std::endl; } } return result.releaseTarget(); }
QSize WellArray::sizeHint() const { ensurePolished(); return gridSize().boundedTo(QSize(640, 480)); }
cuint32_t cgridX () const { return gridSize ().x (); }