int ImageBase::channels() const { if (dimensions() < 3) return 1; return extent(2); }
int ImageBase::right() const { if (dimensions() < 1) return 0; return min(0) + extent(0) - 1; }
int ImageBase::width() const { if (dimensions() < 1) return 1; return extent(0); }
int ImageBase::height() const { if (dimensions() < 2) return 1; return extent(1); }
void QgsRasterInterface::initHistogram( QgsRasterHistogram &theHistogram, int theBandNo, int theBinCount, double theMinimum, double theMaximum, const QgsRectangle & theExtent, int theSampleSize, bool theIncludeOutOfRange ) { theHistogram.bandNumber = theBandNo; theHistogram.minimum = theMinimum; theHistogram.maximum = theMaximum; theHistogram.includeOutOfRange = theIncludeOutOfRange; int mySrcDataType = sourceDataType( theBandNo ); if ( qIsNaN( theHistogram.minimum ) ) { // TODO: this was OK when stats/histogram were calced in provider, // but what TODO in other interfaces? Check for mInput for now. if ( !mInput && mySrcDataType == Qgis::Byte ) { theHistogram.minimum = 0; // see histogram() for shift for rounding } else { // We need statistics -> avoid histogramDefaults in hasHistogram if possible // TODO: use approximated statistics if aproximated histogram is requested // (theSampleSize > 0) QgsRasterBandStats stats = bandStatistics( theBandNo, QgsRasterBandStats::Min, theExtent, theSampleSize ); theHistogram.minimum = stats.minimumValue; } } if ( qIsNaN( theHistogram.maximum ) ) { if ( !mInput && mySrcDataType == Qgis::Byte ) { theHistogram.maximum = 255; } else { QgsRasterBandStats stats = bandStatistics( theBandNo, QgsRasterBandStats::Max, theExtent, theSampleSize ); theHistogram.maximum = stats.maximumValue; } } QgsRectangle myExtent; if ( theExtent.isEmpty() ) { myExtent = extent(); } else { myExtent = extent().intersect( &theExtent ); } theHistogram.extent = myExtent; if ( theSampleSize > 0 ) { // Calc resolution from theSampleSize double xRes, yRes; xRes = yRes = sqrt(( myExtent.width() * myExtent.height() ) / theSampleSize ); // But limit by physical resolution if ( capabilities() & Size ) { double srcXRes = extent().width() / xSize(); double srcYRes = extent().height() / ySize(); if ( xRes < srcXRes ) xRes = srcXRes; if ( yRes < srcYRes ) yRes = srcYRes; } QgsDebugMsgLevel( QString( "xRes = %1 yRes = %2" ).arg( xRes ).arg( yRes ), 4 ); theHistogram.width = static_cast <int>( myExtent.width() / xRes ); theHistogram.height = static_cast <int>( myExtent.height() / yRes ); } else { if ( capabilities() & Size ) { theHistogram.width = xSize(); theHistogram.height = ySize(); } else { theHistogram.width = 1000; theHistogram.height = 1000; } } QgsDebugMsgLevel( QString( "theHistogram.width = %1 theHistogram.height = %2" ).arg( theHistogram.width ).arg( theHistogram.height ), 4 ); int myBinCount = theBinCount; if ( myBinCount == 0 ) { // TODO: this was OK when stats/histogram were calced in provider, // but what TODO in other interfaces? Check for mInput for now. if ( !mInput && mySrcDataType == Qgis::Byte ) { myBinCount = 256; // Cannot store more values in byte } else { // There is no best default value, to display something reasonable in histogram chart, binCount should be small, OTOH, to get precise data for cumulative cut, the number should be big. Because it is easier to define fixed lower value for the chart, we calc optimum binCount for higher resolution (to avoid calculating that where histogram() is used. In any any case, it does not make sense to use more than width*height; myBinCount = theHistogram.width * theHistogram.height; if ( myBinCount > 1000 ) myBinCount = 1000; // for Int16/Int32 make sure bin count <= actual range, because there is no sense in having // bins at fractional values if ( !mInput && ( mySrcDataType == Qgis::Int16 || mySrcDataType == Qgis::Int32 || mySrcDataType == Qgis::UInt16 || mySrcDataType == Qgis::UInt32 ) ) { if ( myBinCount > theHistogram.maximum - theHistogram.minimum + 1 ) myBinCount = int( ceil( theHistogram.maximum - theHistogram.minimum + 1 ) ); } } } theHistogram.binCount = myBinCount; QgsDebugMsgLevel( QString( "theHistogram.binCount = %1" ).arg( theHistogram.binCount ), 4 ); }
BOOST_FORCEINLINE result_type operator()(Expr& e) const { _2D sizee = extent(nt2::numel(boost::proto::child_c<0>(e))); return sizee; }
Expr OutputImageParam::channels() const { user_assert(dimensions() > 2) << "Can't ask for the channels of an image with fewer than three dimensions\n"; return extent(2); }
void btConvexShape::getAabbNonVirtual (const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const { switch (m_shapeType) { case SPHERE_SHAPE_PROXYTYPE: { btSphereShape* sphereShape = (btSphereShape*)this; btScalar radius = sphereShape->getImplicitShapeDimensions().getX();// * convexShape->getLocalScaling().getX(); btScalar margin = radius + sphereShape->getMarginNonVirtual(); const btVector3& center = t.getOrigin(); btVector3 extent(margin,margin,margin); aabbMin = center - extent; aabbMax = center + extent; } break; case CYLINDER_SHAPE_PROXYTYPE: /* fall through */ case BOX_SHAPE_PROXYTYPE: { btBoxShape* convexShape = (btBoxShape*)this; btScalar margin=convexShape->getMarginNonVirtual(); btVector3 halfExtents = convexShape->getImplicitShapeDimensions(); halfExtents += btVector3(margin,margin,margin); btMatrix3x3 abs_b = t.getBasis().absolute(); btVector3 center = t.getOrigin(); btVector3 extent = halfExtents.dot3(abs_b[0], abs_b[1], abs_b[2]); aabbMin = center - extent; aabbMax = center + extent; break; } case TRIANGLE_SHAPE_PROXYTYPE: { btTriangleShape* triangleShape = (btTriangleShape*)this; btScalar margin = triangleShape->getMarginNonVirtual(); for (int i=0;i<3;i++) { btVector3 vec(btScalar(0.),btScalar(0.),btScalar(0.)); vec[i] = btScalar(1.); btVector3 sv = localGetSupportVertexWithoutMarginNonVirtual(vec*t.getBasis()); btVector3 tmp = t(sv); aabbMax[i] = tmp[i]+margin; vec[i] = btScalar(-1.); tmp = t(localGetSupportVertexWithoutMarginNonVirtual(vec*t.getBasis())); aabbMin[i] = tmp[i]-margin; } } break; case CAPSULE_SHAPE_PROXYTYPE: { btCapsuleShape* capsuleShape = (btCapsuleShape*)this; btVector3 halfExtents(capsuleShape->getRadius(),capsuleShape->getRadius(),capsuleShape->getRadius()); int m_upAxis = capsuleShape->getUpAxis(); halfExtents[m_upAxis] = capsuleShape->getRadius() + capsuleShape->getHalfHeight(); halfExtents += btVector3(capsuleShape->getMarginNonVirtual(),capsuleShape->getMarginNonVirtual(),capsuleShape->getMarginNonVirtual()); btMatrix3x3 abs_b = t.getBasis().absolute(); btVector3 center = t.getOrigin(); btVector3 extent = halfExtents.dot3(abs_b[0], abs_b[1], abs_b[2]); aabbMin = center - extent; aabbMax = center + extent; } break; case CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE: case CONVEX_HULL_SHAPE_PROXYTYPE: { btPolyhedralConvexAabbCachingShape* convexHullShape = (btPolyhedralConvexAabbCachingShape*)this; btScalar margin = convexHullShape->getMarginNonVirtual(); convexHullShape->getNonvirtualAabb (t, aabbMin, aabbMax, margin); } break; default: #ifndef __SPU__ this->getAabb (t, aabbMin, aabbMax); #else btAssert (0); #endif break; } // should never reach here btAssert (0); }
Expr OutputImageParam::width() const { user_assert(dimensions() > 0) << "Can't ask for the width of a zero-dimensional image\n"; return extent(0); }
Expr OutputImageParam::height() const { user_assert(dimensions() > 1) << "Can't ask for the height of a zero or one-dimensional image\n"; return extent(1); }
QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWidget *parent, Qt::WindowFlags flags ) : QDialog( parent, flags ) , mDock( nullptr ) , mLayer( theLayer ) , mRubberBand( nullptr ) , mCurrentSearchWidgetWrapper( nullptr ) { setupUi( this ); Q_FOREACH ( const QgsField& field, mLayer->fields() ) { mVisibleFields.append( field.name() ); } // Fix selection color on loosing focus (Windows) setStyleSheet( QgisApp::instance()->styleSheet() ); setAttribute( Qt::WA_DeleteOnClose ); QSettings settings; // Initialize the window geometry restoreGeometry( settings.value( "/Windows/BetterAttributeTable/geometry" ).toByteArray() ); myDa = new QgsDistanceArea(); myDa->setSourceCrs( mLayer->crs() ); myDa->setEllipsoidalMode( QgisApp::instance()->mapCanvas()->mapSettings().hasCrsTransformEnabled() ); myDa->setEllipsoid( QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", GEO_NONE ) ); mEditorContext.setDistanceArea( *myDa ); mEditorContext.setVectorLayerTools( QgisApp::instance()->vectorLayerTools() ); QgsFeatureRequest r; if ( mLayer->geometryType() != QGis::NoGeometry && settings.value( "/qgis/attributeTableBehaviour", QgsAttributeTableFilterModel::ShowAll ).toInt() == QgsAttributeTableFilterModel::ShowVisible ) { QgsMapCanvas *mc = QgisApp::instance()->mapCanvas(); QgsRectangle extent( mc->mapSettings().mapToLayerCoordinates( theLayer, mc->extent() ) ); r.setFilterRect( extent ); QgsGeometry *g = QgsGeometry::fromRect( extent ); mRubberBand = new QgsRubberBand( mc, QGis::Polygon ); mRubberBand->setToGeometry( g, theLayer ); delete g; mActionShowAllFilter->setText( tr( "Show All Features In Initial Canvas Extent" ) ); } // Initialize dual view mMainView->init( mLayer, QgisApp::instance()->mapCanvas(), r, mEditorContext ); QgsAttributeTableConfig config = mLayer->attributeTableConfig(); mMainView->setAttributeTableConfig( config ); // Initialize filter gui elements mFilterActionMapper = new QSignalMapper( this ); mFilterColumnsMenu = new QMenu( this ); mActionFilterColumnsMenu->setMenu( mFilterColumnsMenu ); mApplyFilterButton->setDefaultAction( mActionApplyFilter ); // Set filter icon in a couple of places QIcon filterIcon = QgsApplication::getThemeIcon( "/mActionFilter2.svg" ); mActionShowAllFilter->setIcon( filterIcon ); mActionAdvancedFilter->setIcon( filterIcon ); mActionSelectedFilter->setIcon( filterIcon ); mActionVisibleFilter->setIcon( filterIcon ); mActionEditedFilter->setIcon( filterIcon ); // Connect filter signals connect( mActionAdvancedFilter, SIGNAL( triggered() ), SLOT( filterExpressionBuilder() ) ); connect( mActionShowAllFilter, SIGNAL( triggered() ), SLOT( filterShowAll() ) ); connect( mActionSelectedFilter, SIGNAL( triggered() ), SLOT( filterSelected() ) ); connect( mActionVisibleFilter, SIGNAL( triggered() ), SLOT( filterVisible() ) ); connect( mActionEditedFilter, SIGNAL( triggered() ), SLOT( filterEdited() ) ); connect( mFilterActionMapper, SIGNAL( mapped( QObject* ) ), SLOT( filterColumnChanged( QObject* ) ) ); connect( mFilterQuery, SIGNAL( returnPressed() ), SLOT( filterQueryAccepted() ) ); connect( mActionApplyFilter, SIGNAL( triggered() ), SLOT( filterQueryAccepted() ) ); connect( mSetStyles, SIGNAL( pressed() ), SLOT( openConditionalStyles() ) ); // info from layer to table connect( mLayer, SIGNAL( editingStarted() ), this, SLOT( editingToggled() ) ); connect( mLayer, SIGNAL( editingStopped() ), this, SLOT( editingToggled() ) ); connect( mLayer, SIGNAL( layerDeleted() ), this, SLOT( close() ) ); connect( mLayer, SIGNAL( selectionChanged() ), this, SLOT( updateTitle() ) ); connect( mLayer, SIGNAL( featureAdded( QgsFeatureId ) ), this, SLOT( updateTitle() ) ); connect( mLayer, SIGNAL( featuresDeleted( QgsFeatureIds ) ), this, SLOT( updateTitle() ) ); connect( mLayer, SIGNAL( attributeAdded( int ) ), this, SLOT( columnBoxInit() ) ); connect( mLayer, SIGNAL( attributeDeleted( int ) ), this, SLOT( columnBoxInit() ) ); // connect table info to window connect( mMainView, SIGNAL( filterChanged() ), this, SLOT( updateTitle() ) ); connect( mMainView, SIGNAL( filterExpressionSet( QString, QgsAttributeForm::FilterType ) ), this, SLOT( formFilterSet( QString, QgsAttributeForm::FilterType ) ) ); connect( mMainView, SIGNAL( formModeChanged( QgsAttributeForm::Mode ) ), this, SLOT( viewModeChanged( QgsAttributeForm::Mode ) ) ); // info from table to application connect( this, SIGNAL( saveEdits( QgsMapLayer * ) ), QgisApp::instance(), SLOT( saveEdits( QgsMapLayer * ) ) ); bool myDockFlag = settings.value( "/qgis/dockAttributeTable", false ).toBool(); if ( myDockFlag ) { mDock = new QgsAttributeTableDock( tr( "Attribute table - %1 (%n Feature(s))", "feature count", mMainView->featureCount() ).arg( mLayer->name() ), QgisApp::instance() ); mDock->setAllowedAreas( Qt::BottomDockWidgetArea | Qt::TopDockWidgetArea ); mDock->setWidget( this ); connect( this, SIGNAL( destroyed() ), mDock, SLOT( close() ) ); QgisApp::instance()->addDockWidget( Qt::BottomDockWidgetArea, mDock ); } columnBoxInit(); updateTitle(); mRemoveSelectionButton->setIcon( QgsApplication::getThemeIcon( "/mActionUnselectAttributes.png" ) ); mSelectAllButton->setIcon( QgsApplication::getThemeIcon( "/mActionSelectAll.svg" ) ); mSelectedToTopButton->setIcon( QgsApplication::getThemeIcon( "/mActionSelectedToTop.png" ) ); mCopySelectedRowsButton->setIcon( QgsApplication::getThemeIcon( "/mActionCopySelected.png" ) ); mZoomMapToSelectedRowsButton->setIcon( QgsApplication::getThemeIcon( "/mActionZoomToSelected.svg" ) ); mPanMapToSelectedRowsButton->setIcon( QgsApplication::getThemeIcon( "/mActionPanToSelected.svg" ) ); mInvertSelectionButton->setIcon( QgsApplication::getThemeIcon( "/mActionInvertSelection.svg" ) ); mToggleEditingButton->setIcon( QgsApplication::getThemeIcon( "/mActionToggleEditing.svg" ) ); mSaveEditsButton->setIcon( QgsApplication::getThemeIcon( "/mActionSaveEdits.svg" ) ); mDeleteSelectedButton->setIcon( QgsApplication::getThemeIcon( "/mActionDeleteSelected.svg" ) ); mOpenFieldCalculator->setIcon( QgsApplication::getThemeIcon( "/mActionCalculateField.png" ) ); mAddAttribute->setIcon( QgsApplication::getThemeIcon( "/mActionNewAttribute.png" ) ); mRemoveAttribute->setIcon( QgsApplication::getThemeIcon( "/mActionDeleteAttribute.png" ) ); mTableViewButton->setIcon( QgsApplication::getThemeIcon( "/mActionOpenTable.svg" ) ); mAttributeViewButton->setIcon( QgsApplication::getThemeIcon( "/mActionPropertyItem.png" ) ); mExpressionSelectButton->setIcon( QgsApplication::getThemeIcon( "/mIconExpressionSelect.svg" ) ); mAddFeature->setIcon( QgsApplication::getThemeIcon( "/mActionNewTableRow.png" ) ); // toggle editing bool canChangeAttributes = mLayer->dataProvider()->capabilities() & QgsVectorDataProvider::ChangeAttributeValues; bool canDeleteFeatures = mLayer->dataProvider()->capabilities() & QgsVectorDataProvider::DeleteFeatures; bool canAddAttributes = mLayer->dataProvider()->capabilities() & QgsVectorDataProvider::AddAttributes; bool canDeleteAttributes = mLayer->dataProvider()->capabilities() & QgsVectorDataProvider::DeleteAttributes; bool canAddFeatures = mLayer->dataProvider()->capabilities() & QgsVectorDataProvider::AddFeatures; mToggleEditingButton->blockSignals( true ); mToggleEditingButton->setCheckable( true ); mToggleEditingButton->setChecked( mLayer->isEditable() ); mToggleEditingButton->setEnabled(( canChangeAttributes || canDeleteFeatures || canAddAttributes || canDeleteAttributes || canAddFeatures ) && !mLayer->readOnly() ); mToggleEditingButton->blockSignals( false ); mSaveEditsButton->setEnabled( mToggleEditingButton->isEnabled() && mLayer->isEditable() ); mReloadButton->setEnabled( ! mLayer->isEditable() ); mAddAttribute->setEnabled(( canChangeAttributes || canAddAttributes ) && mLayer->isEditable() ); mDeleteSelectedButton->setEnabled( canDeleteFeatures && mLayer->isEditable() ); mAddFeature->setEnabled( canAddFeatures && mLayer->isEditable() ); mAddFeature->setHidden( !canAddFeatures ); mMainViewButtonGroup->setId( mTableViewButton, QgsDualView::AttributeTable ); mMainViewButtonGroup->setId( mAttributeViewButton, QgsDualView::AttributeEditor ); // Load default attribute table filter QgsAttributeTableFilterModel::FilterMode defaultFilterMode = ( QgsAttributeTableFilterModel::FilterMode ) settings.value( "/qgis/attributeTableBehaviour", QgsAttributeTableFilterModel::ShowAll ).toInt(); switch ( defaultFilterMode ) { case QgsAttributeTableFilterModel::ShowVisible: filterVisible(); break; case QgsAttributeTableFilterModel::ShowSelected: filterSelected(); break; case QgsAttributeTableFilterModel::ShowAll: default: filterShowAll(); break; } mUpdateExpressionText->registerGetExpressionContextCallback( &_getExpressionContext, mLayer ); mFieldModel = new QgsFieldModel( this ); mFieldModel->setLayer( mLayer ); mFieldCombo->setModel( mFieldModel ); connect( mRunFieldCalc, SIGNAL( clicked() ), this, SLOT( updateFieldFromExpression() ) ); connect( mRunFieldCalcSelected, SIGNAL( clicked() ), this, SLOT( updateFieldFromExpressionSelected() ) ); // NW TODO Fix in 2.6 - Doesn't work with field model for some reason. // connect( mUpdateExpressionText, SIGNAL( returnPressed() ), this, SLOT( updateFieldFromExpression() ) ); connect( mUpdateExpressionText, SIGNAL( fieldChanged( QString, bool ) ), this, SLOT( updateButtonStatus( QString, bool ) ) ); mUpdateExpressionText->setLayer( mLayer ); mUpdateExpressionText->setLeftHandButtonStyle( true ); int initialView = settings.value( "/qgis/attributeTableView", -1 ).toInt(); if ( initialView < 0 ) { initialView = settings.value( "/qgis/attributeTableLastView", QgsDualView::AttributeTable ).toInt(); } mMainView->setView( static_cast< QgsDualView::ViewMode >( initialView ) ); mMainViewButtonGroup->button( initialView )->setChecked( true ); connect( mToggleMultiEditButton, SIGNAL( toggled( bool ) ), mMainView, SLOT( setMultiEditEnabled( bool ) ) ); connect( mSearchFormButton, SIGNAL( toggled( bool ) ), mMainView, SLOT( toggleSearchMode( bool ) ) ); updateMultiEditButtonState(); editingToggled(); }
bool Projekt::Init() { if (!D3D11App::Init()) return false; // Initialize effects, input layouts and texture manager Effects::InitAll(mDirect3D->GetDevice()); InputLayouts::InitAll(mDirect3D->GetDevice()); mTextureMgr.init(mDirect3D->GetDevice()); // Initialize wireframe render state D3D11_RASTERIZER_DESC wireFrameDesc; ZeroMemory(&wireFrameDesc, sizeof(D3D11_RASTERIZER_DESC)); wireFrameDesc.FillMode = D3D11_FILL_WIREFRAME; wireFrameDesc.CullMode = D3D11_CULL_BACK; wireFrameDesc.FrontCounterClockwise = false; wireFrameDesc.DepthClipEnable = true; HR(mDirect3D->GetDevice()->CreateRasterizerState(&wireFrameDesc, &WireFrameRS)); //-------------------------------------------------------- // Create sky //-------------------------------------------------------- mSky = new Sky(mDirect3D->GetDevice(), L"Data/Textures/snowcube1024.dds", 5000.0f); //-------------------------------------------------------- // Create terrain //-------------------------------------------------------- // Describe terrain Terrain::InitInfo tInitInfo; tInitInfo.HeightMapFilename = L"Data/Textures/Heightmaps/terrain.raw"; tInitInfo.LayerMapFilename0 = L"Data/Textures/grass.dds"; tInitInfo.LayerMapFilename1 = L"Data/Textures/darkdirt.dds"; tInitInfo.LayerMapFilename2 = L"Data/Textures/stone.dds"; tInitInfo.LayerMapFilename3 = L"Data/Textures/lightdirt.dds"; tInitInfo.LayerMapFilename4 = L"Data/Textures/snow.dds"; tInitInfo.BlendMapFilename = L"Data/Textures/blend.dds"; tInitInfo.HeightScale = 50.0f; tInitInfo.HeightmapWidth = 2049; tInitInfo.HeightmapHeight = 2049; tInitInfo.CellSpacing = 0.5f; // Initialize terrain mTerrain.Init(mDirect3D->GetDevice(), mDirect3D->GetImmediateContext(), tInitInfo); //-------------------------------------------------------- // Particle systems //-------------------------------------------------------- mRandomTexSRV = d3dHelper::CreateRandomTexture1DSRV(mDirect3D->GetDevice()); std::vector<std::wstring> flares; flares.push_back(L"Data\\Textures\\flare0.dds"); mFlareTexSRV = d3dHelper::CreateTexture2DArraySRV(mDirect3D->GetDevice(), mDirect3D->GetImmediateContext(), flares); mFire.init(mDirect3D->GetDevice(), Effects::FireFX, mFlareTexSRV, mRandomTexSRV, 500); mFire.setEmitPos(XMFLOAT3(65.0f, 5.0f, 0.0f)); //-------------------------------------------------------- // Create shadow map //-------------------------------------------------------- mShadowMapSize = 2048; mShadowMap = new ShadowMap(mDirect3D->GetDevice(), mShadowMapSize, mShadowMapSize); //-------------------------------------------------------- // Load models //-------------------------------------------------------- mGenericModel = new GenericModel(mDirect3D->GetDevice(), mTextureMgr, "Data\\Models\\Collada\\duck.dae", L"Data\\Models\\Collada\\"); //mSkinnedModel = new GenericSkinnedModel(mDirect3D->GetDevice(), mTextureMgr, "Data\\Models\\Collada\\AnimTest\\test_Collada_DAE.dae", L"Data\\Models\\Collada\\AnimTest\\"); mPlayerModel = new GenericModel(mDirect3D->GetDevice(), mTextureMgr, "Data\\Models\\OBJ\\Cop\\cop.obj", L"Data\\Models\\OBJ\\Cop\\"); Player::InitProperties playerProp; playerProp.PlayerID = 0; playerProp.Nickname = "Hyzor"; playerProp.Speed = 1.0f; playerProp.Health = 1.0f; playerProp.Position = XMFLOAT3(0.0f, 0.0f, 0.0f); playerProp.Scale = XMFLOAT3(1.0f, 1.0f, 1.0f); playerProp.Angle = 0.0f; playerProp.Model = mPlayerModel; mPlayer.Init(playerProp); //-------------------------------------------------------- // Create model instances //-------------------------------------------------------- GenericModelInstance genericInstance; genericInstance.model = mGenericModel; // GenericSkinnedModelInstance genSkinnedInstance; // genSkinnedInstance.model = mSkinnedModel; // genSkinnedInstance.FinalTransforms.resize(mSkinnedModel->skinnedData.getBoneCount()); // genSkinnedInstance.ClipName = "animation"; // genSkinnedInstance.TimePos = 0.0f; //-------------------------------------------------------- // Scale, rotate and move model instances //-------------------------------------------------------- XMMATRIX modelScale = XMMatrixScaling(1.0f, 1.0f, 1.0f); XMMATRIX modelRot = XMMatrixRotationY(0.0f); XMMATRIX modelOffset = XMMatrixTranslation(0.0f, 0.0f, 0.0f); //modelScale = XMMatrixScaling(0.1f, 0.1f, 0.1f); modelOffset = XMMatrixTranslation(-30.0f, 15.0f, -110.0f); XMStoreFloat4x4(&genericInstance.world, modelScale*modelRot*modelOffset); // modelOffset = XMMatrixTranslation(50.0f, 15.0f, -110.0f); // XMStoreFloat4x4(&genSkinnedInstance.world, modelScale*modelRot*modelOffset); //-------------------------------------------------------- // Insert model instances to the vector //-------------------------------------------------------- mGenericInstances.push_back(genericInstance); /* mGenSkinnedInstances.push_back(genSkinnedInstance);*/ //-------------------------------------------------------- // Compute scene bounding box //-------------------------------------------------------- XMFLOAT3 minPt(+MathHelper::infinity, +MathHelper::infinity, +MathHelper::infinity); XMFLOAT3 maxPt(-MathHelper::infinity, -MathHelper::infinity, -MathHelper::infinity); // Get vertex positions from all models for (UINT i = 0; i < mGenericInstances.size(); ++i) { for (UINT j = 0; j < mGenericInstances[i].model->vertices.size(); ++j) { XMFLOAT3 vPos = mGenericInstances[i].model->vertices[j]->position; minPt.x = MathHelper::getMin(minPt.x, vPos.x); minPt.y = MathHelper::getMin(minPt.x, vPos.x); minPt.z = MathHelper::getMin(minPt.x, vPos.x); maxPt.x = MathHelper::getMax(maxPt.x, vPos.x); maxPt.y = MathHelper::getMax(maxPt.x, vPos.x); maxPt.z = MathHelper::getMax(maxPt.x, vPos.x); } } // Get vertex positions from all skinned models // for (UINT i = 0; i < mGenSkinnedInstances.size(); ++i) // { // for (UINT j = 0; j < mGenSkinnedInstances[i].model->vertices.size(); ++j) // { // XMFLOAT3 vPos = mGenSkinnedInstances[i].model->vertices[j]->position; // // minPt.x = MathHelper::getMin(minPt.x, vPos.x); // minPt.y = MathHelper::getMin(minPt.x, vPos.x); // minPt.z = MathHelper::getMin(minPt.x, vPos.x); // // maxPt.x = MathHelper::getMax(maxPt.x, vPos.x); // maxPt.y = MathHelper::getMax(maxPt.x, vPos.x); // maxPt.z = MathHelper::getMax(maxPt.x, vPos.x); // } // } // Now continue with terrain vertex positions for (UINT i = 0; i < mTerrain.getPatchVertices().size(); ++i) { XMFLOAT3 vPos = mTerrain.getPatchVertices()[i].position; minPt.x = MathHelper::getMin(minPt.x, vPos.x); minPt.y = MathHelper::getMin(minPt.x, vPos.x); minPt.z = MathHelper::getMin(minPt.x, vPos.x); maxPt.x = MathHelper::getMax(maxPt.x, vPos.x); maxPt.y = MathHelper::getMax(maxPt.x, vPos.x); maxPt.z = MathHelper::getMax(maxPt.x, vPos.x); } // Sphere center is at half of these new dimensions mSceneBounds.Center = XMFLOAT3( 0.5f*(minPt.x + maxPt.x), 0.5f*(minPt.y + maxPt.y), 0.5f*(minPt.z + maxPt.z)); // Calculate the sphere radius XMFLOAT3 extent(0.5f*(maxPt.x - minPt.x), 0.5f*(maxPt.y - minPt.y), 0.5f*(maxPt.z - minPt.z)); mSceneBounds.Radius = sqrtf(extent.x*extent.x + extent.y*extent.y + extent.z*extent.z); OnResize(); return true; }
query_iterator begin() { return tree_.query_in_box(extent()); }
int ImageBase::bottom() const { if (dimensions() < 2) return 0; return min(1) + extent(1) - 1; }
Expr OutputImageParam::right() const { user_assert(dimensions() > 0) << "Can't ask for the right of a zero-dimensional image\n"; return Internal::Add::make(min(0), Internal::Sub::make(extent(0), 1)); }
int HGRAD_WEDGE_C2_FEM_Test01(const bool verbose) { Teuchos::RCP<std::ostream> outStream; Teuchos::oblackholestream bhs; // outputs nothing if (verbose) outStream = Teuchos::rcp(&std::cout, false); else outStream = Teuchos::rcp(&bhs, false); Teuchos::oblackholestream oldFormatState; oldFormatState.copyfmt(std::cout); typedef typename Kokkos::Impl::is_space<DeviceSpaceType>::host_mirror_space::execution_space HostSpaceType ; *outStream << "DeviceSpace:: "; DeviceSpaceType::print_configuration(*outStream, false); *outStream << "HostSpace:: "; HostSpaceType::print_configuration(*outStream, false); *outStream << "===============================================================================\n" << "| |\n" << "| Unit Test (Basis_HGRAD_WEDGE_C2_FEM) |\n" << "| |\n" << "| 1) Conversion of Dof tags into Dof ordinals and back |\n" << "| 2) Basis values for VALUE, GRAD, and Dk operators |\n" << "| |\n" << "| Questions? Contact Pavel Bochev ([email protected]), |\n" << "| Denis Ridzal ([email protected]), |\n" << "| Kara Peterson ([email protected]), |\n" << "| Kyungjoo Kim ([email protected]). |\n" << "| |\n" << "| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" << "| Trilinos website: http://trilinos.sandia.gov |\n" << "| |\n" << "===============================================================================\n"; typedef Kokkos::DynRankView<ValueType,DeviceSpaceType> DynRankView; typedef Kokkos::DynRankView<ValueType,HostSpaceType> DynRankViewHost; #define ConstructWithLabel(obj, ...) obj(#obj, __VA_ARGS__) const ValueType tol = tolerence(); int errorFlag = 0; // for virtual function, value and point types are declared in the class typedef ValueType outputValueType; typedef ValueType pointValueType; Basis_HGRAD_WEDGE_C2_FEM<DeviceSpaceType,outputValueType,pointValueType> wedgeBasis; *outStream << "\n" << "===============================================================================\n" << "| TEST 1: constructors and exceptions |\n" << "===============================================================================\n"; try { ordinal_type nthrow = 0, ncatch = 0; #ifdef HAVE_INTREPID2_DEBUG // Define array containing the 4 vertices of the reference WEDGE and its center. DynRankView ConstructWithLabel(wedgeNodes, 18, 3); // Generic array for the output values; needs to be properly resized depending on the operator type const ordinal_type numFields = wedgeBasis.getCardinality(); const ordinal_type numPoints = wedgeNodes.extent(0); const ordinal_type spaceDim = wedgeBasis.getBaseCellTopology().getDimension(); DynRankView vals("vals", numFields, numPoints); DynRankView vals_vec("vals", numFields, numPoints, spaceDim); { // exception #1: CURL cannot be applied to scalar functions INTREPID2_TEST_ERROR_EXPECTED( wedgeBasis.getValues(vals_vec, wedgeNodes, OPERATOR_DIV) ); // exception #2: DIV cannot be applied to scalar functions INTREPID2_TEST_ERROR_EXPECTED( wedgeBasis.getValues(vals_vec, wedgeNodes, OPERATOR_DIV) ); } // Exceptions 3-7: all bf tags/bf Ids below are wrong and should cause getDofOrdinal() and // getDofTag() to access invalid array elements thereby causing bounds check exception { // exception #3 INTREPID2_TEST_ERROR_EXPECTED( wedgeBasis.getDofOrdinal(3,0,0) ); // exception #4 INTREPID2_TEST_ERROR_EXPECTED( wedgeBasis.getDofOrdinal(1,1,1) ); // exception #5 INTREPID2_TEST_ERROR_EXPECTED( wedgeBasis.getDofOrdinal(0,9,0) ); // exception #6 INTREPID2_TEST_ERROR_EXPECTED( wedgeBasis.getDofTag(numFields) ); // exception #7 INTREPID2_TEST_ERROR_EXPECTED( wedgeBasis.getDofTag(-1) ); } // Exceptions 8-18 test exception handling with incorrectly dimensioned input/output arrays { // exception #8: input points array must be of rank-2 DynRankView ConstructWithLabel( badPoints1, 4, 5, 3); INTREPID2_TEST_ERROR_EXPECTED( wedgeBasis.getValues(vals, badPoints1, OPERATOR_VALUE) ); } { // exception #9 dimension 1 in the input point array must equal space dimension of the cell DynRankView ConstructWithLabel( badPoints2, 4, spaceDim + 1); INTREPID2_TEST_ERROR_EXPECTED( wedgeBasis.getValues(vals, badPoints2, OPERATOR_VALUE) ); } { // exception #10 output values must be of rank-2 for OPERATOR_VALUE DynRankView ConstructWithLabel( badVals1, 4, 3, 1); INTREPID2_TEST_ERROR_EXPECTED( wedgeBasis.getValues(badVals1, wedgeNodes, OPERATOR_VALUE) ); } { // exception #11 output values must be of rank-3 for OPERATOR_GRAD DynRankView ConstructWithLabel( badVals2, 4, 3); INTREPID2_TEST_ERROR_EXPECTED( wedgeBasis.getValues(badVals2, wedgeNodes, OPERATOR_GRAD) ); // exception #12 output values must be of rank-3 for OPERATOR_D1 INTREPID2_TEST_ERROR_EXPECTED( wedgeBasis.getValues(badVals2, wedgeNodes, OPERATOR_D1) ); // exception #13 output values must be of rank-3 for OPERATOR_D2 INTREPID2_TEST_ERROR_EXPECTED( wedgeBasis.getValues(badVals2, wedgeNodes, OPERATOR_D2) ); } { // exception #14 incorrect 0th dimension of output array (must equal number of basis functions) DynRankView ConstructWithLabel( badVals3, numFields + 1, numPoints); INTREPID2_TEST_ERROR_EXPECTED( wedgeBasis.getValues(badVals3, wedgeNodes, OPERATOR_VALUE) ); } { // exception #15 incorrect 1st dimension of output array (must equal number of points) DynRankView ConstructWithLabel( badVals4, numFields, numPoints + 1); INTREPID2_TEST_ERROR_EXPECTED( wedgeBasis.getValues(badVals4, wedgeNodes, OPERATOR_VALUE) ); } { // exception #16: incorrect 2nd dimension of output array (must equal the space dimension) DynRankView ConstructWithLabel( badVals5, numFields, numPoints, spaceDim - 1); INTREPID2_TEST_ERROR_EXPECTED( wedgeBasis.getValues(badVals5, wedgeNodes, OPERATOR_GRAD) ); } { // exception #17: incorrect 2nd dimension of output array (must equal D2 cardinality in 3D) DynRankView ConstructWithLabel( badVals6, numFields, numPoints, 40); INTREPID2_TEST_ERROR_EXPECTED( wedgeBasis.getValues(badVals6, wedgeNodes, OPERATOR_D2) ); // exception #18: incorrect 2nd dimension of output array (must equal D3 cardinality in 3D) INTREPID2_TEST_ERROR_EXPECTED( wedgeBasis.getValues(badVals6, wedgeNodes, OPERATOR_D3) ); } #endif if (nthrow != ncatch) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; *outStream << "# of catch ("<< ncatch << ") is different from # of throw (" << ncatch << ")\n"; } } catch (std::exception err) { *outStream << "UNEXPECTED ERROR !!! ----------------------------------------------------------\n"; *outStream << err.what() << '\n'; *outStream << "-------------------------------------------------------------------------------" << "\n\n"; errorFlag = -1000; } *outStream << "\n" << "===============================================================================\n" << "| TEST 2: correctness of tag to enum and enum to tag lookups |\n" << "===============================================================================\n"; try { const ordinal_type numFields = wedgeBasis.getCardinality(); const auto allTags = wedgeBasis.getAllDofTags(); // Loop over all tags, lookup the associated dof enumeration and then lookup the tag again const ordinal_type dofTagSize = allTags.extent(0); for (ordinal_type i=0;i<dofTagSize;++i) { const auto bfOrd = wedgeBasis.getDofOrdinal(allTags(i,0), allTags(i,1), allTags(i,2)); const auto myTag = wedgeBasis.getDofTag(bfOrd); if( !( (myTag(0) == allTags(i,0)) && (myTag(1) == allTags(i,1)) && (myTag(2) == allTags(i,2)) && (myTag(3) == allTags(i,3)) ) ) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; *outStream << " getDofOrdinal( {" << allTags(i,0) << ", " << allTags(i,1) << ", " << allTags(i,2) << ", " << allTags(i,3) << "}) = " << bfOrd <<" but \n"; *outStream << " getDofTag(" << bfOrd << ") = { " << myTag(0) << ", " << myTag(1) << ", " << myTag(2) << ", " << myTag(3) << "}\n"; } } // Now do the same but loop over basis functions for (ordinal_type bfOrd=0;bfOrd<numFields;++bfOrd) { const auto myTag = wedgeBasis.getDofTag(bfOrd); const auto myBfOrd = wedgeBasis.getDofOrdinal(myTag(0), myTag(1), myTag(2)); if( bfOrd != myBfOrd) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; *outStream << " getDofTag(" << bfOrd << ") = { " << myTag(0) << ", " << myTag(1) << ", " << myTag(2) << ", " << myTag(3) << "} but getDofOrdinal({" << myTag(0) << ", " << myTag(1) << ", " << myTag(2) << ", " << myTag(3) << "} ) = " << myBfOrd << "\n"; } } } catch (std::logic_error err) { *outStream << err.what() << "\n\n"; errorFlag = -1000; } *outStream << "\n" << "===============================================================================\n" << "| TEST 3: correctness of basis function values |\n" << "===============================================================================\n"; outStream -> precision(20); // VALUE: correct basis function values in (F,P) format const ValueType basisValues[] = { 1.00, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.00, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.00, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.00, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.00, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, 1.00, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 1.00, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 1.00, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ 1.00, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.00, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.00, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.00, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.00, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, 1.00, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 1.00, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 1.00, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ 1.00, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.00 }; // GRAD and D1 values are stored in (F,P,D) format in a data file. Read file and do the test std::vector<ValueType> basisGrads; // Flat array for the gradient values. { std::ifstream dataFile("../testdata/WEDGE_C2_GradVals.dat"); INTREPID2_TEST_FOR_EXCEPTION( !dataFile.good(), std::logic_error, ">>> ERROR (HGRAD_WEDGE_C2/test01): could not open GRAD values data file, test aborted."); while (!dataFile.eof() ){ ValueType temp; std::string line; // string for one line of input file std::getline(dataFile, line); // get next line from file std::stringstream data_line(line); // convert to stringstream while (data_line >> temp) // extract value from line basisGrads.push_back(temp); // push into vector } } //D2: flat array with the values of D2 applied to basis functions. Multi-index is (F,P,D2cardinality) std::vector<ValueType> basisD2; { std::ifstream dataFile("../testdata/WEDGE_C2_D2Vals.dat"); INTREPID2_TEST_FOR_EXCEPTION( !dataFile.good(), std::logic_error, ">>> ERROR (HGRAD_WEDGE_C2/test01): could not open D2 values data file, test aborted."); while (!dataFile.eof() ){ ValueType temp; std::string line; // string for one line of input file std::getline(dataFile, line); // get next line from file std::stringstream data_line(line); // convert to stringstream while (data_line >> temp) // extract value from line basisD2.push_back(temp); // push into vector } } //D3: flat array with the values of D3 applied to basis functions. Multi-index is (F,P,D3cardinality) std::vector<ValueType> basisD3; { std::ifstream dataFile("../testdata/WEDGE_C2_D3Vals.dat"); INTREPID2_TEST_FOR_EXCEPTION( !dataFile.good(), std::logic_error, ">>> ERROR (HGRAD_WEDGE_C2/test01): could not open D3 values data file, test aborted."); while (!dataFile.eof() ){ ValueType temp; std::string line; // string for one line of input file std::getline(dataFile, line); // get next line from file std::stringstream data_line(line); // convert to stringstream while (data_line >> temp) // extract value from line basisD3.push_back(temp); // push into vector } } //D4: flat array with the values of D3 applied to basis functions. Multi-index is (F,P,D4cardinality) std::vector<ValueType> basisD4; { std::ifstream dataFile("../testdata/WEDGE_C2_D4Vals.dat"); INTREPID2_TEST_FOR_EXCEPTION( !dataFile.good(), std::logic_error, ">>> ERROR (HGRAD_WEDGE_C2/test01): could not open D4 values data file, test aborted."); while (!dataFile.eof() ){ ValueType temp; std::string line; // string for one line of input file std::getline(dataFile, line); // get next line from file std::stringstream data_line(line); // convert to stringstream while (data_line >> temp) // extract value from line basisD4.push_back(temp); // push into vector } } try { DynRankViewHost ConstructWithLabel(wedgeNodesHost, 18, 3); wedgeNodesHost(0,0) = 0.0; wedgeNodesHost(0,1) = 0.0; wedgeNodesHost(0,2) = -1.0; wedgeNodesHost(1,0) = 1.0; wedgeNodesHost(1,1) = 0.0; wedgeNodesHost(1,2) = -1.0; wedgeNodesHost(2,0) = 0.0; wedgeNodesHost(2,1) = 1.0; wedgeNodesHost(2,2) = -1.0; wedgeNodesHost(3,0) = 0.0; wedgeNodesHost(3,1) = 0.0; wedgeNodesHost(3,2) = 1.0; wedgeNodesHost(4,0) = 1.0; wedgeNodesHost(4,1) = 0.0; wedgeNodesHost(4,2) = 1.0; wedgeNodesHost(5,0) = 0.0; wedgeNodesHost(5,1) = 1.0; wedgeNodesHost(5,2) = 1.0; wedgeNodesHost(6,0) = 0.5; wedgeNodesHost(6,1) = 0.0; wedgeNodesHost(6,2) = -1.0; wedgeNodesHost(7,0) = 0.5; wedgeNodesHost(7,1) = 0.5; wedgeNodesHost(7,2) = -1.0; wedgeNodesHost(8,0) = 0.0; wedgeNodesHost(8,1) = 0.5; wedgeNodesHost(8,2) = -1.0; wedgeNodesHost(9,0) = 0.0; wedgeNodesHost(9,1) = 0.0; wedgeNodesHost(9,2) = 0.0; wedgeNodesHost(10,0)= 1.0; wedgeNodesHost(10,1)= 0.0; wedgeNodesHost(10,2)= 0.0; wedgeNodesHost(11,0)= 0.0; wedgeNodesHost(11,1)= 1.0; wedgeNodesHost(11,2)= 0.0; wedgeNodesHost(12,0)= 0.5; wedgeNodesHost(12,1)= 0.0; wedgeNodesHost(12,2)= 1.0; wedgeNodesHost(13,0)= 0.5; wedgeNodesHost(13,1)= 0.5; wedgeNodesHost(13,2)= 1.0; wedgeNodesHost(14,0)= 0.0; wedgeNodesHost(14,1)= 0.5; wedgeNodesHost(14,2)= 1.0; wedgeNodesHost(15,0)= 0.5; wedgeNodesHost(15,1)= 0.0; wedgeNodesHost(15,2)= 0.0; wedgeNodesHost(16,0)= 0.5; wedgeNodesHost(16,1)= 0.5; wedgeNodesHost(16,2)= 0.0; wedgeNodesHost(17,0)= 0.0; wedgeNodesHost(17,1)= 0.5; wedgeNodesHost(17,2)= 0.0; auto wedgeNodes = Kokkos::create_mirror_view(typename DeviceSpaceType::memory_space(), wedgeNodesHost); Kokkos::deep_copy(wedgeNodes, wedgeNodesHost); // Dimensions for the output arrays: const ordinal_type numFields = wedgeBasis.getCardinality(); const ordinal_type numPoints = wedgeNodes.extent(0); const ordinal_type spaceDim = wedgeBasis.getBaseCellTopology().getDimension(); const ordinal_type D2Cardin = getDkCardinality(OPERATOR_D2, spaceDim); const ordinal_type D3Cardin = getDkCardinality(OPERATOR_D3, spaceDim); const ordinal_type D4Cardin = getDkCardinality(OPERATOR_D4, spaceDim); // Check VALUE of basis functions: resize vals to rank-2 container: { DynRankView vals = DynRankView("vals", numFields, numPoints); wedgeBasis.getValues(vals, wedgeNodes, OPERATOR_VALUE); auto vals_host = Kokkos::create_mirror_view(typename HostSpaceType::memory_space(), vals); Kokkos::deep_copy(vals_host, vals); for (ordinal_type i = 0; i < numFields; ++i) { for (ordinal_type j = 0; j < numPoints; ++j) { const ordinal_type l = i + j * numFields; if (std::abs(vals_host(i,j) - basisValues[l]) > tol) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; // Output the multi-index of the value where the error is: *outStream << " At multi-index { "; *outStream << i << " ";*outStream << j << " "; *outStream << "} computed value: " << vals_host(i,j) << " but reference value: " << basisValues[l] << "\n"; } } } } // Check GRAD of basis function: resize vals to rank-3 container { DynRankView vals = DynRankView("vals", numFields, numPoints, spaceDim); wedgeBasis.getValues(vals, wedgeNodes, OPERATOR_GRAD); auto vals_host = Kokkos::create_mirror_view(typename HostSpaceType::memory_space(), vals); Kokkos::deep_copy(vals_host, vals); for (ordinal_type i = 0; i < numFields; ++i) { for (ordinal_type j = 0; j < numPoints; ++j) { for (ordinal_type k = 0; k < spaceDim; ++k) { // basisGrads is (F,P,D), compute offset: const ordinal_type l = k + j * spaceDim + i * spaceDim * numPoints; if (std::abs(vals_host(i,j,k) - basisGrads[l]) > tol) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; // Output the multi-index of the value where the error is: *outStream << " At multi-index { "; *outStream << i << " ";*outStream << j << " ";*outStream << k << " "; *outStream << "} computed grad component: " << vals_host(i,j,k) << " but reference grad component: " << basisGrads[l] << "\n"; } } } } } // Check D1 of basis function (do not resize vals because it has the correct size: D1 = GRAD) { DynRankView vals = DynRankView("vals", numFields, numPoints, spaceDim); wedgeBasis.getValues(vals, wedgeNodes, OPERATOR_D1); auto vals_host = Kokkos::create_mirror_view(typename HostSpaceType::memory_space(), vals); Kokkos::deep_copy(vals_host, vals); for (ordinal_type i = 0; i < numFields; ++i) { for (ordinal_type j = 0; j < numPoints; ++j) { for (ordinal_type k = 0; k < spaceDim; ++k) { // basisGrads is (F,P,D), compute offset: const ordinal_type l = k + j * spaceDim + i * spaceDim * numPoints; if (std::abs(vals_host(i,j,k) - basisGrads[l]) > tol) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; // Output the multi-index of the value where the error is: *outStream << " At multi-index { "; *outStream << i << " ";*outStream << j << " ";*outStream << k << " "; *outStream << "} computed D1 component: " << vals_host(i,j,k) << " but reference D1 component: " << basisGrads[l] << "\n"; } } } } } // Check D2 of basis function { DynRankView vals = DynRankView("vals", numFields, numPoints, D2Cardin); wedgeBasis.getValues(vals, wedgeNodes, OPERATOR_D2); auto vals_host = Kokkos::create_mirror_view(typename HostSpaceType::memory_space(), vals); Kokkos::deep_copy(vals_host, vals); for (ordinal_type i = 0; i < numFields; ++i) { for (ordinal_type j = 0; j < numPoints; ++j) { for (ordinal_type k = 0; k < D2Cardin; ++k) { // basisGrads is (F,P,D), compute offset: const ordinal_type l = k + j * D2Cardin + i * D2Cardin * numPoints; if (std::abs(vals_host(i,j,k) - basisD2[l]) > tol) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; // Output the multi-index of the value where the error is: *outStream << " At multi-index { "; *outStream << i << " ";*outStream << j << " ";*outStream << k << " "; *outStream << "} computed D2 component: " << vals_host(i,j,k) << " but reference D2 component: " << basisGrads[l] << "\n"; } } } } } // Check D3 of basis function { DynRankView vals = DynRankView("vals", numFields, numPoints, D3Cardin); wedgeBasis.getValues(vals, wedgeNodes, OPERATOR_D3); auto vals_host = Kokkos::create_mirror_view(typename HostSpaceType::memory_space(), vals); Kokkos::deep_copy(vals_host, vals); for (ordinal_type i = 0; i < numFields; ++i) { for (ordinal_type j = 0; j < numPoints; ++j) { for (ordinal_type k = 0; k < D3Cardin; ++k) { // basisGrads is (F,P,D), compute offset: const ordinal_type l = k + j * D3Cardin + i * D3Cardin * numPoints; if (std::abs(vals_host(i,j,k) - basisD3[l]) > tol) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; // Output the multi-index of the value where the error is: *outStream << " At multi-index { "; *outStream << i << " ";*outStream << j << " ";*outStream << k << " "; *outStream << "} computed D3 component: " << vals_host(i,j,k) << " but reference D3 component: " << basisD3[l] << "\n"; } } } } } // Check D4 of basis function { DynRankView vals = DynRankView("vals", numFields, numPoints, D4Cardin); wedgeBasis.getValues(vals, wedgeNodes, OPERATOR_D4); auto vals_host = Kokkos::create_mirror_view(typename HostSpaceType::memory_space(), vals); Kokkos::deep_copy(vals_host, vals); for (ordinal_type i = 0; i < numFields; ++i) { for (ordinal_type j = 0; j < numPoints; ++j) { for (ordinal_type k = 0; k < D4Cardin; ++k) { // basisGrads is (F,P,D), compute offset: const ordinal_type l = k + j * D4Cardin + i * D4Cardin * numPoints; if (std::abs(vals_host(i,j,k) - basisD4[l]) > tol) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; // Output the multi-index of the value where the error is: *outStream << " At multi-index { "; *outStream << i << " ";*outStream << j << " ";*outStream << k << " "; *outStream << "} computed D4 component: " << vals_host(i,j,k) << " but reference D4 component: " << basisD4[l] << "\n"; } } } } } // Check all higher derivatives - must be zero. { const EOperator ops[] = { OPERATOR_D5, OPERATOR_D6, OPERATOR_D7, OPERATOR_D8, OPERATOR_D9, OPERATOR_D10, OPERATOR_MAX }; for (auto h=0;ops[h]!=OPERATOR_MAX;++h) { const auto op = ops[h]; const ordinal_type DkCardin = getDkCardinality(op, spaceDim); DynRankView vals("vals", numFields, numPoints, DkCardin); wedgeBasis.getValues(vals, wedgeNodes, op); auto vals_host = Kokkos::create_mirror_view(typename HostSpaceType::memory_space(), vals); Kokkos::deep_copy(vals_host, vals); for (ordinal_type i1=0;i1<numFields; i1++) for (ordinal_type i2=0;i2<numPoints; i2++) for (ordinal_type i3=0;i3<DkCardin; i3++) { if (std::abs(vals_host(i1,i2,i3)) > tol) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; // Get the multi-index of the value where the error is and the operator order const auto ord = Intrepid2::getOperatorOrder(op); *outStream << " At multi-index { "<<i1<<" "<<i2 <<" "<<i3; *outStream << "} computed D"<< ord <<" component: " << vals_host(i1,i2,i3) << " but reference D" << ord << " component: 0 \n"; } } } } } catch (std::exception err) { *outStream << err.what() << "\n\n"; errorFlag = -1000; } if (errorFlag != 0) std::cout << "End Result: TEST FAILED\n"; else std::cout << "End Result: TEST PASSED\n"; // reset format state of std::cout std::cout.copyfmt(oldFormatState); return errorFlag; }
Expr OutputImageParam::bottom() const { user_assert(dimensions() > 1) << "Can't ask for the bottom of a zero- or one-dimensional image\n"; return Internal::Add::make(min(1), Internal::Sub::make(extent(1), 1)); }
int HCURL_TRI_I1_FEM_Test01(const bool verbose) { Teuchos::RCP<std::ostream> outStream; Teuchos::oblackholestream bhs; // outputs nothing if (verbose) outStream = Teuchos::rcp(&std::cout, false); else outStream = Teuchos::rcp(&bhs, false); Teuchos::oblackholestream oldFormatState; oldFormatState.copyfmt(std::cout); typedef typename Kokkos::Impl::is_space<DeviceSpaceType>::host_mirror_space::execution_space HostSpaceType ; *outStream << "DeviceSpace:: "; DeviceSpaceType::print_configuration(*outStream, false); *outStream << "HostSpace:: "; HostSpaceType::print_configuration(*outStream, false); *outStream << "===============================================================================\n" << "| |\n" << "| Unit Test (Basis_HCURL_TRI_I1_FEM) |\n" << "| |\n" << "| 1) Conversion of Dof tags into Dof ordinals and back |\n" << "| 2) Basis values for VALUE and CURL operators |\n" << "| |\n" << "| Questions? Contact Pavel Bochev ([email protected]), |\n" << "| Denis Ridzal ([email protected]), |\n" << "| Kara Peterson ([email protected]). |\n" << "| Kyungjoo Kim ([email protected]). |\n" << "| |\n" << "| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" << "| Trilinos website: http://trilinos.sandia.gov |\n" << "| |\n" << "===============================================================================\n"; typedef Kokkos::DynRankView<ValueType,DeviceSpaceType> DynRankView; typedef Kokkos::DynRankView<ValueType,HostSpaceType> DynRankViewHost; #define ConstructWithLabel(obj, ...) obj(#obj, __VA_ARGS__) const ValueType tol = tolerence(); int errorFlag = 0; // for virtual function, value and point types are declared in the class typedef ValueType outputValueType; typedef ValueType pointValueType; Basis_HCURL_TRI_I1_FEM<DeviceSpaceType,outputValueType,pointValueType> triBasis; *outStream << "\n" << "===============================================================================\n" << "| TEST 1: Basis creation, exception testing |\n" << "===============================================================================\n"; try{ ordinal_type nthrow = 0, ncatch = 0; #ifdef HAVE_INTREPID2_DEBUG // Define array containing the 3 vertices of the reference TRI and its 3 edge midpoints. DynRankView ConstructWithLabel(triNodes, 7, 2); // Generic array for the output values; needs to be properly resized depending on the operator type const ordinal_type cardinality = triBasis.getCardinality(); const ordinal_type numPoints = triNodes.extent(0); DynRankView vals; vals = DynRankView("vals", cardinality, numPoints); { // exception #1: GRAD cannot be applied to HCURL functions INTREPID2_TEST_ERROR_EXPECTED( triBasis.getValues(vals, triNodes, OPERATOR_GRAD) ); } { // exception #2: DIV cannot be applied to HCURL functions INTREPID2_TEST_ERROR_EXPECTED( triBasis.getValues(vals, triNodes, OPERATOR_DIV) ); } // Exceptions 3-7: all bf tags/bf Ids below are wrong and should cause getDofOrdinal() and // getDofTag() to access invalid array elements thereby causing bounds check exception { // exception #3 INTREPID2_TEST_ERROR_EXPECTED( triBasis.getDofOrdinal(3,0,0) ); // exception #4 INTREPID2_TEST_ERROR_EXPECTED( triBasis.getDofOrdinal(1,1,1) ); // exception #5 INTREPID2_TEST_ERROR_EXPECTED( triBasis.getDofOrdinal(0,4,1) ); // exception #6 INTREPID2_TEST_ERROR_EXPECTED( triBasis.getDofTag(cardinality) ); // exception #7 INTREPID2_TEST_ERROR_EXPECTED( triBasis.getDofTag(-1) ); } // Exceptions 8-15 test exception handling with incorrectly dimensioned input/output arrays { // exception #8: input points array must be of rank-2 DynRankView ConstructWithLabel(badPoints1, 4, 5, 3); INTREPID2_TEST_ERROR_EXPECTED( triBasis.getValues(vals, badPoints1, OPERATOR_VALUE) ); } // exception #9 dimension 1 in the input point array must equal space dimension of the cell { DynRankView ConstructWithLabel(badPoints2, 4, triBasis.getBaseCellTopology().getDimension() + 1); INTREPID2_TEST_ERROR_EXPECTED( triBasis.getValues(vals, badPoints2, OPERATOR_VALUE) ); } { // exception #10 output values must be of rank-3 for OPERATOR_VALUE in 2D DynRankView ConstructWithLabel(badVals1, 4, 3); INTREPID2_TEST_ERROR_EXPECTED( triBasis.getValues(badVals1, triNodes, OPERATOR_VALUE) ); } { // exception #11 output values must be of rank-2 for OPERATOR_CURL DynRankView ConstructWithLabel(badCurls1,4,3,2); INTREPID2_TEST_ERROR_EXPECTED( triBasis.getValues(badCurls1, triNodes, OPERATOR_CURL) ); } { // exception #12 incorrect 0th dimension of output array (must equal number of basis functions) DynRankView ConstructWithLabel(badVals2, triBasis.getCardinality() + 1, triNodes.extent(0), triBasis.getBaseCellTopology().getDimension()); INTREPID2_TEST_ERROR_EXPECTED( triBasis.getValues(badVals2, triNodes, OPERATOR_VALUE) ) ; } { // exception #13 incorrect 1st dimension of output array (must equal number of points) DynRankView ConstructWithLabel(badVals3, triBasis.getCardinality(), triNodes.extent(0) + 1, triBasis.getBaseCellTopology().getDimension() ); INTREPID2_TEST_ERROR_EXPECTED( triBasis.getValues(badVals3, triNodes, OPERATOR_VALUE) ) ; } { // exception #14: incorrect 2nd dimension of output array for VALUE (must equal the space dimension) DynRankView ConstructWithLabel(badVals4, triBasis.getCardinality(), triNodes.extent(0), triBasis.getBaseCellTopology().getDimension() - 1); INTREPID2_TEST_ERROR_EXPECTED( triBasis.getValues(badVals4, triNodes, OPERATOR_VALUE) ) ; } // exception #15: D2 cannot be applied to HCURL functions // resize vals to rank-3 container with dimensions (num. basis functions, num. points, arbitrary) // vals.resize(triBasis.getCardinality(), // triNodes.extent(0), // Intrepid2::getDkCardinality(OPERATOR_D2, triBasis.getBaseCellTopology().getDimension())); // INTREPID2_TEST_ERROR_EXPECTED( triBasis.getValues(vals, triNodes, OPERATOR_D2) ); #endif // Check if number of thrown exceptions matches the one we expect if (nthrow != ncatch) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; *outStream << "# of catch ("<< ncatch << ") is different from # of throw (" << nthrow << ")\n"; } } catch (std::logic_error err) { *outStream << "UNEXPECTED ERROR !!! ----------------------------------------------------------\n"; *outStream << err.what() << '\n'; *outStream << "-------------------------------------------------------------------------------" << "\n\n"; errorFlag = -1000; } *outStream << "\n" << "===============================================================================\n" << "| TEST 2: correctness of tag to enum and enum to tag lookups |\n" << "===============================================================================\n"; // all tags are on host space try{ const auto allTags = triBasis.getAllDofTags(); // Loop over all tags, lookup the associated dof enumeration and then lookup the tag again const ordinal_type dofTagSize = allTags.extent(0); for (ordinal_type i = 0; i < dofTagSize; ++i) { const auto bfOrd = triBasis.getDofOrdinal(allTags(i,0), allTags(i,1), allTags(i,2)); const auto myTag = triBasis.getDofTag(bfOrd); if( !( (myTag(0) == allTags(i,0)) && (myTag(1) == allTags(i,1)) && (myTag(2) == allTags(i,2)) && (myTag(3) == allTags(i,3)) ) ) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; *outStream << " getDofOrdinal( {" << allTags(i,0) << ", " << allTags(i,1) << ", " << allTags(i,2) << ", " << allTags(i,3) << "}) = " << bfOrd <<" but \n"; *outStream << " getDofTag(" << bfOrd << ") = { " << myTag(0) << ", " << myTag(1) << ", " << myTag(2) << ", " << myTag(3) << "}\n"; } } // Now do the same but loop over basis functions for( ordinal_type bfOrd = 0; bfOrd < triBasis.getCardinality(); bfOrd++) { const auto myTag = triBasis.getDofTag(bfOrd); const auto myBfOrd = triBasis.getDofOrdinal(myTag(0), myTag(1), myTag(2)); if( bfOrd != myBfOrd) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; *outStream << " getDofTag(" << bfOrd << ") = { " << myTag(0) << ", " << myTag(1) << ", " << myTag(2) << ", " << myTag(3) << "} but getDofOrdinal({" << myTag(0) << ", " << myTag(1) << ", " << myTag(2) << ", " << myTag(3) << "} ) = " << myBfOrd << "\n"; } } } catch (std::logic_error err){ *outStream << err.what() << "\n\n"; errorFlag = -1000; }; *outStream << "\n" << "===============================================================================\n" << "| TEST 3: correctness of basis function values |\n" << "===============================================================================\n"; outStream -> precision(20); // VALUE: correct values in (P,F,D) layout const ValueType basisValues[] = { 1.000, 0, 0, 0, 0, -1.000, 1.000, 1.000, 0, 1.000, 0, 0, 0, 0, \ -1.000, 0, -1.000, -1.000, 1.000, 0.5000, 0, 0.5000, 0, -0.5000, \ 0.5000, 0.5000, -0.5000, 0.5000, -0.5000, -0.5000, 0.5000, 0, \ -0.5000, 0, -0.5000, -1.000, 0.7500, 0.2500, -0.2500, 0.2500, \ -0.2500, -0.7500}; // CURL: correct values in (P,F) layout const ValueType basisCurls[] = { 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 }; try{ DynRankViewHost ConstructWithLabel(triNodesHost, 7, 2); triNodesHost(0,0) = 0.0; triNodesHost(0,1) = 0.0; triNodesHost(1,0) = 1.0; triNodesHost(1,1) = 0.0; triNodesHost(2,0) = 0.0; triNodesHost(2,1) = 1.0; // edge midpoints triNodesHost(3,0) = 0.5; triNodesHost(3,1) = 0.0; triNodesHost(4,0) = 0.5; triNodesHost(4,1) = 0.5; triNodesHost(5,0) = 0.0; triNodesHost(5,1) = 0.5; // Inside Triangle triNodesHost(6,0) = 0.25; triNodesHost(6,1) = 0.25; auto triNodes = Kokkos::create_mirror_view(typename DeviceSpaceType::memory_space(), triNodesHost); Kokkos::deep_copy(triNodes, triNodesHost); // Dimensions for the output arrays: const ordinal_type cardinality = triBasis.getCardinality(); const ordinal_type numPoints = triNodes.extent(0); const ordinal_type spaceDim = triBasis.getBaseCellTopology().getDimension(); { // Check VALUE of basis functions: resize vals to rank-3 container: DynRankView ConstructWithLabel(vals, cardinality, numPoints, spaceDim); triBasis.getValues(vals, triNodes, OPERATOR_VALUE); auto vals_host = Kokkos::create_mirror_view(typename HostSpaceType::memory_space(), vals); Kokkos::deep_copy(vals_host, vals); for (ordinal_type i = 0; i < cardinality; ++i) { for (ordinal_type j = 0; j < numPoints; ++j) { for (ordinal_type k = 0; k < spaceDim; ++k) { // compute offset for (P,F,D) data layout: indices are P->j, F->i, D->k ordinal_type l = k + i * spaceDim + j * spaceDim * cardinality; if (std::abs(vals_host(i,j,k) - basisValues[l]) > tol) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; // Output the multi-index of the value where the error is: *outStream << " At multi-index { "; *outStream << i << " ";*outStream << j << " ";*outStream << k << " "; *outStream << "} computed value: " << vals_host(i,j,k) << " but reference value: " << basisValues[l] << "\n"; } } } } } { // Check CURL of basis function: resize vals to rank-2 container DynRankView ConstructWithLabel(vals, cardinality, numPoints); triBasis.getValues(vals, triNodes, OPERATOR_CURL); auto vals_host = Kokkos::create_mirror_view(typename HostSpaceType::memory_space(), vals); Kokkos::deep_copy(vals_host, vals); for (ordinal_type i = 0; i < cardinality; ++i) { for (ordinal_type j = 0; j < numPoints; ++j) { ordinal_type l = i + j * cardinality; if (std::abs(vals_host(i,j) - basisCurls[l]) > tol) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; // Output the multi-index of the value where the error is: *outStream << " At multi-index { "; *outStream << i << " ";*outStream << j << " "; *outStream << "} computed curl component: " << vals_host(i,j) << " but reference curl component: " << basisCurls[l] << "\n"; } } } } } //end try // Catch unexpected errors catch (std::logic_error err) { *outStream << err.what() << "\n\n"; errorFlag = -1000; }; *outStream << "\n" << "===============================================================================\n" << "| TEST 4: correctness of DoF locations |\n" << "===============================================================================\n"; try{ const ordinal_type cardinality = triBasis.getCardinality(); const ordinal_type spaceDim = triBasis.getBaseCellTopology().getDimension(); // Check exceptions. ordinal_type nthrow = 0, ncatch = 0; #ifdef HAVE_INTREPID2_DEBUG { DynRankView ConstructWithLabel(badVals, 1, 2, 3); INTREPID2_TEST_ERROR_EXPECTED( triBasis.getDofCoords(badVals) ); } { DynRankView ConstructWithLabel(badVals, 4, 2); INTREPID2_TEST_ERROR_EXPECTED( triBasis.getDofCoords(badVals) ); } { DynRankView ConstructWithLabel(badVals, 4, 3); INTREPID2_TEST_ERROR_EXPECTED( triBasis.getDofCoords(badVals) ); } #endif // Check if number of thrown exceptions matches the one we expect if (nthrow != ncatch) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; *outStream << "# of catch ("<< ncatch << ") is different from # of throw (" << ncatch << ")\n"; } // Check mathematical correctness DynRankView ConstructWithLabel(bvals, cardinality, cardinality, spaceDim); DynRankView ConstructWithLabel(cvals, cardinality, spaceDim); DynRankView ConstructWithLabel(dofCoeffs, cardinality, spaceDim); triBasis.getDofCoeffs(dofCoeffs); triBasis.getDofCoords(cvals); triBasis.getValues(bvals, cvals, OPERATOR_VALUE); auto cvals_host = Kokkos::create_mirror_view(typename HostSpaceType::memory_space(), cvals); Kokkos::deep_copy(cvals_host, cvals); auto dofCoeffs_host = Kokkos::create_mirror_view(typename HostSpaceType::memory_space(), dofCoeffs); Kokkos::deep_copy(dofCoeffs_host, dofCoeffs); auto bvals_host = Kokkos::create_mirror_view(typename HostSpaceType::memory_space(), bvals); Kokkos::deep_copy(bvals_host, bvals); char buffer[120]; for (ordinal_type i=0; i<cardinality; ++i) { for (ordinal_type j=0; j<cardinality; ++j) { double dofValue = 0.0; for(ordinal_type d=0;d<spaceDim;++d) dofValue += bvals_host(i,j,d)*dofCoeffs_host(j,d); if ((i != j) && (std::abs(dofValue - 0.0) > tol )) { errorFlag++; sprintf(buffer, "\nValue of basis function %d at (%6.4e, %6.4e) is %6.4e but should be %6.4e!\n", i, cvals_host(i,0), cvals_host(i,1), dofValue, 0.0); *outStream << buffer; } else if ((i == j) && (std::abs(dofValue - 1.0) > tol )) { errorFlag++; sprintf(buffer, "\nValue of basis function %d at (%6.4e, %6.4e) is %6.4e but should be %6.4e!\n", i, cvals_host(i,0), cvals_host(i,1), dofValue, 1.0); *outStream << buffer; } } } } catch (std::logic_error err){ *outStream << err.what() << "\n\n"; errorFlag = -1000; }; if (errorFlag != 0) std::cout << "End Result: TEST FAILED\n"; else std::cout << "End Result: TEST PASSED\n"; // reset format state of std::cout std::cout.copyfmt(oldFormatState); return errorFlag; }
QRect KisPixelSelection::selectedRect() const { return extent(); }
/** By default, this method assumes a symmetric neighborhood relation * and refers to the non-directed version of extent(). */ plint DataProcessor2D::extent(int direction) const { return extent(); }
QgsRasterBlock * QgsRasterDataProvider::block( int theBandNo, QgsRectangle const & theExtent, int theWidth, int theHeight ) { QgsDebugMsg( QString( "theBandNo = %1 theWidth = %2 theHeight = %3" ).arg( theBandNo ).arg( theWidth ).arg( theHeight ) ); QgsDebugMsg( QString( "theExtent = %1" ).arg( theExtent.toString() ) ); QgsRasterBlock *block = new QgsRasterBlock( dataType( theBandNo ), theWidth, theHeight, noDataValue( theBandNo ) ); if ( block->isEmpty() ) { QgsDebugMsg( "Couldn't create raster block" ); return block; } // Read necessary extent only QgsRectangle tmpExtent = extent().intersect( &theExtent ); if ( tmpExtent.isEmpty() ) { QgsDebugMsg( "Extent outside provider extent" ); block->setIsNoData(); return block; } double xRes = theExtent.width() / theWidth; double yRes = theExtent.height() / theHeight; double tmpXRes, tmpYRes; double providerXRes = 0; double providerYRes = 0; if ( capabilities() & ExactResolution ) { providerXRes = extent().width() / xSize(); providerYRes = extent().height() / ySize(); tmpXRes = qMax( providerXRes, xRes ); tmpYRes = qMax( providerYRes, yRes ); if ( doubleNear( tmpXRes, xRes ) ) tmpXRes = xRes; if ( doubleNear( tmpYRes, yRes ) ) tmpYRes = yRes; } else { tmpXRes = xRes; tmpYRes = yRes; } if ( tmpExtent != theExtent || tmpXRes > xRes || tmpYRes > yRes ) { // Read smaller extent or lower resolution // Calculate row/col limits (before tmpExtent is aligned) int fromRow = qRound(( theExtent.yMaximum() - tmpExtent.yMaximum() ) / yRes ); int toRow = qRound(( theExtent.yMaximum() - tmpExtent.yMinimum() ) / yRes ) - 1; int fromCol = qRound(( tmpExtent.xMinimum() - theExtent.xMinimum() ) / xRes ) ; int toCol = qRound(( tmpExtent.xMaximum() - theExtent.xMinimum() ) / xRes ) - 1; QgsDebugMsg( QString( "fromRow = %1 toRow = %2 fromCol = %3 toCol = %4" ).arg( fromRow ).arg( toRow ).arg( fromCol ).arg( toCol ) ); if ( fromRow < 0 || fromRow >= theHeight || toRow < 0 || toRow >= theHeight || fromCol < 0 || fromCol >= theWidth || toCol < 0 || toCol >= theWidth ) { // Should not happen QgsDebugMsg( "Row or column limits out of range" ); return block; } // If lower source resolution is used, the extent must beS aligned to original // resolution to avoid possible shift due to resampling if ( tmpXRes > xRes ) { int col = floor(( tmpExtent.xMinimum() - extent().xMinimum() ) / providerXRes ); tmpExtent.setXMinimum( extent().xMinimum() + col * providerXRes ); col = ceil(( tmpExtent.xMaximum() - extent().xMinimum() ) / providerXRes ); tmpExtent.setXMaximum( extent().xMinimum() + col * providerXRes ); } if ( tmpYRes > yRes ) { int row = floor(( extent().yMaximum() - tmpExtent.yMaximum() ) / providerYRes ); tmpExtent.setYMaximum( extent().yMaximum() - row * providerYRes ); row = ceil(( extent().yMaximum() - tmpExtent.yMinimum() ) / providerYRes ); tmpExtent.setYMinimum( extent().yMaximum() - row * providerYRes ); } int tmpWidth = qRound( tmpExtent.width() / tmpXRes ); int tmpHeight = qRound( tmpExtent.height() / tmpYRes ); tmpXRes = tmpExtent.width() / tmpWidth; tmpYRes = tmpExtent.height() / tmpHeight; QgsDebugMsg( QString( "Reading smaller block tmpWidth = %1 theHeight = %2" ).arg( tmpWidth ).arg( tmpHeight ) ); QgsDebugMsg( QString( "tmpExtent = %1" ).arg( tmpExtent.toString() ) ); block->setIsNoData(); QgsRasterBlock *tmpBlock = new QgsRasterBlock( dataType( theBandNo ), tmpWidth, tmpHeight, noDataValue( theBandNo ) ); readBlock( theBandNo, tmpExtent, tmpWidth, tmpHeight, tmpBlock->data() ); int pixelSize = dataTypeSize( theBandNo ); double xMin = theExtent.xMinimum(); double yMax = theExtent.yMaximum(); double tmpXMin = tmpExtent.xMinimum(); double tmpYMax = tmpExtent.yMaximum(); for ( int row = fromRow; row <= toRow; row++ ) { double y = yMax - ( row + 0.5 ) * yRes; int tmpRow = floor(( tmpYMax - y ) / tmpYRes ); for ( int col = fromCol; col <= toCol; col++ ) { double x = xMin + ( col + 0.5 ) * xRes; int tmpCol = floor(( x - tmpXMin ) / tmpXRes ); if ( tmpRow < 0 || tmpRow >= tmpHeight || tmpCol < 0 || tmpCol >= tmpWidth ) { QgsDebugMsg( "Source row or column limits out of range" ); block->setIsNoData(); // so that the problem becomes obvious and fixed delete tmpBlock; return block; } size_t tmpIndex = tmpRow * tmpWidth + tmpCol; size_t index = row * theWidth + col; char *tmpBits = tmpBlock->bits( tmpIndex ); char *bits = block->bits( index ); if ( !tmpBits ) { QgsDebugMsg( QString( "Cannot get input block data tmpRow = %1 tmpCol = %2 tmpIndex = %3." ).arg( tmpRow ).arg( tmpCol ).arg( tmpIndex ) ); continue; } if ( !bits ) { QgsDebugMsg( "Cannot set output block data." ); continue; } memcpy( bits, tmpBits, pixelSize ); } } delete tmpBlock; } else { readBlock( theBandNo, theExtent, theWidth, theHeight, block->data() ); } // apply user no data values // TODO: there are other readBlock methods where no data are not applied QList<QgsRasterBlock::Range> myNoDataRangeList = userNoDataValue( theBandNo ); if ( !myNoDataRangeList.isEmpty() ) { double myNoDataValue = noDataValue( theBandNo ); size_t size = theWidth * theHeight; for ( size_t i = 0; i < size; i++ ) { double value = block->value( i ); if ( QgsRasterBlock::valueInRange( value, myNoDataRangeList ) ) { block->setValue( i, myNoDataValue ); } } } return block; }