//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RicRangeFilterInsertExec::redo()
{
    RimCellRangeFilter* rangeFilter = createRangeFilter();
    if (rangeFilter)
    {
        size_t index = m_cellRangeFilterCollection->rangeFilters.index(m_cellRangeFilter);
        CVF_ASSERT(index < m_cellRangeFilterCollection->rangeFilters.size());

        m_cellRangeFilterCollection->rangeFilters.insertAt(static_cast<int>(index), rangeFilter);

        rangeFilter->setDefaultValues();
        applyCommandDataOnFilter(rangeFilter);

        m_cellRangeFilterCollection->updateDisplayModeNotifyManagedViews(NULL);

        m_cellRangeFilterCollection->updateConnectedEditors();

        RiuMainWindow::instance()->selectAsCurrentItem(rangeFilter);
    }
}
Exemple #2
0
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSummaryCurveCreator::copyEnsembleCurveAndAddToCurveSet(const RimSummaryCurve* curve,
                                                               RimEnsembleCurveSet*   curveSet,
                                                               bool                   forceVisible)
{
    RimSummaryCurve* curveCopy =
        dynamic_cast<RimSummaryCurve*>(curve->xmlCapability()->copyByXmlSerialization(caf::PdmDefaultObjectFactory::instance()));
    CVF_ASSERT(curveCopy);

    if (forceVisible)
    {
        curveCopy->setCurveVisiblity(true);
    }

    curveSet->addCurve(curveCopy);

    // The curve creator is not a descendant of the project, and need to be set manually
    curveCopy->setSummaryCaseY(curve->summaryCaseY());
    curveCopy->initAfterReadRecursively();
    curveCopy->loadDataAndUpdate(false);
}
Exemple #3
0
double EarClipTesselator::calculateProjectedPolygonArea() const
{
    CVF_ASSERT(m_X > -1 && m_Y > -1);

    double A = 0;

    std::list<size_t>::const_iterator p = m_polygonIndices.end();
    --p;

    std::list<size_t>::const_iterator q = m_polygonIndices.begin();
    while (q != m_polygonIndices.end())
    {
        A += (*m_nodeCoords)[*p][m_X] * (*m_nodeCoords)[*q][m_Y] - (*m_nodeCoords)[*q][m_X]*(*m_nodeCoords)[*p][m_Y];

        p = q;
        ++q;
    }

    return A*0.5;
}
//--------------------------------------------------------------------------------------------------
///  
//--------------------------------------------------------------------------------------------------
void PerformanceInfo::update(const PerformanceInfo& perf)
{
    totalDrawTime               += perf.totalDrawTime;
    computeVisiblePartsTime     += perf.computeVisiblePartsTime;
    buildRenderQueueTime        += perf.buildRenderQueueTime;
    sortRenderQueueTime         += perf.sortRenderQueueTime;
    renderEngineTime            += perf.renderEngineTime;
    visiblePartsCount           += perf.visiblePartsCount;
    renderedPartsCount          += perf.renderedPartsCount;
    vertexCount                 += perf.vertexCount;
    triangleCount               += perf.triangleCount;
    openGLPrimitiveCount        += perf.openGLPrimitiveCount;
    applyRenderStateCount       += perf.applyRenderStateCount;
    shaderProgramChangesCount   += perf.shaderProgramChangesCount;

    CVF_ASSERT(m_nextHistoryItem >= 0 && m_nextHistoryItem < NUM_PERFORMANCE_HISTORY_ITEMS);
    m_totalDrawTimeHistory[m_nextHistoryItem] = totalDrawTime;
    m_nextHistoryItem++;
    if (m_nextHistoryItem >= NUM_PERFORMANCE_HISTORY_ITEMS) m_nextHistoryItem = 0;
}
Exemple #5
0
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimGridCollection::fieldChangedByUi(const caf::PdmFieldHandle* changedField,
                                         const QVariant&            oldValue,
                                         const QVariant&            newValue)
{
    if (changedField == &m_isActive)
    {
        RimGridView* rimView = nullptr;
        this->firstAncestorOrThisOfType(rimView);
        CVF_ASSERT(rimView);

        if (rimView) rimView->showGridCells(m_isActive);

        updateUiIconFromState(m_isActive);
    }

    RimGridView* rimView = nullptr;
    this->firstAncestorOrThisOfType(rimView);

    rimView->scheduleCreateDisplayModelAndRedraw();
}
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
cvf::Variant PropertyXmlSerializer::arrayVariantFromXmlElement(const XmlElement& xmlArrayVariantElement)
{
    CVF_ASSERT(xmlArrayVariantElement.name().toLower() == "array");

    std::vector<Variant> arr;

    const XmlElement* xmlElem = xmlArrayVariantElement.firstChildElement();
    while (xmlElem)
    {
        Variant variant = variantFromXmlElement(*xmlElem);
        if (variant.isValid())
        {
            arr.push_back(variant);
        }

        xmlElem = xmlElem->nextSiblingElement();
    }

    return Variant(arr);
}
Exemple #7
0
bool EarClipTesselator::isTriangleValid( std::list<size_t>::const_iterator u, std::list<size_t>::const_iterator v, std::list<size_t>::const_iterator w) const
{
    CVF_ASSERT(m_X > -1 && m_Y > -1);

    cvf::Vec3d A = (*m_nodeCoords)[*u];
    cvf::Vec3d B = (*m_nodeCoords)[*v];
    cvf::Vec3d C = (*m_nodeCoords)[*w];

    if (  m_areaTolerance > (((B[m_X]-A[m_X])*(C[m_Y]-A[m_Y])) - ((B[m_Y]-A[m_Y])*(C[m_X]-A[m_X]))) ) return false;

    std::list<size_t>::const_iterator c;
    std::list<size_t>::const_iterator outside;
    for (c = m_polygonIndices.begin(); c != m_polygonIndices.end(); ++c)
    {
        // The polygon points that actually make up the triangle candidate does not count
        // (but the same points on different positions in the polygon does! 
        // Except those one off the triangle, that references the start or end of the triangle)

        if ( (c == u) || (c == v) || (c == w)) continue;

        // Originally the below tests was not included which resulted in missing triangles sometimes

        outside = w; ++outside; if (outside == m_polygonIndices.end()) outside = m_polygonIndices.begin();
        if (c == outside && *c == *u) 
        {
            continue;
        }

        outside = u; if (outside == m_polygonIndices.begin()) outside = m_polygonIndices.end(); --outside; 
        if (c == outside && *c == *w) 
        {
            continue;
        }

        cvf::Vec3d P = (*m_nodeCoords)[*c];

        if (isPointInsideTriangle(A, B, C, P)) return false;
    }

    return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaSocketServer::slotReadyRead()
{
    switch (m_readState)
    {
        case ReadingCommand :
        {
            readCommandFromOctave();
            break;
        }

        case ReadingPropertyData :
        {
            readPropertyDataFromOctave();
            break;
        }

        default:
            CVF_ASSERT(false);
            break;
    }
}
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void CategoryMapper::recomputeMaxTexCoord()
{
    const uint numColors = static_cast<uint>(m_colors.size());
    if (numColors == 0)
    {
        m_maxTexCoord = 1.0;
        return;
    }

    const uint numPixelsPerColor = m_textureSize / numColors;
    if (numPixelsPerColor == 0)
    {
        m_maxTexCoord = 1.0;
        return;
    }

    uint texturePixelsInUse = numColors*numPixelsPerColor;
    CVF_ASSERT(texturePixelsInUse <= m_textureSize);

    m_maxTexCoord = static_cast<double>(texturePixelsInUse) / static_cast<double>(m_textureSize);
}
//--------------------------------------------------------------------------------------------------
/// Update the bounding box of this node (recursive)
//--------------------------------------------------------------------------------------------------
void ModelBasicTreeNode::updateBoundingBoxesRecursive()
{
    m_boundingBox.reset();

    uint numChildren = childCount();
    uint i;
    for (i = 0; i < numChildren; i++)
    {
        ModelBasicTreeNode* c = child(i);
        CVF_ASSERT(c);

        c->updateBoundingBoxesRecursive();
        m_boundingBox.add(c->boundingBox());
    }

    if (m_partList.notNull())
    {
        m_partList->updateBoundingBoxesRecursive();
        m_boundingBox.add(m_partList->boundingBox());
    }
}
//--------------------------------------------------------------------------------------------------
/// Set or add a uniform to the UniformSet
/// 
/// If a uniform with the same name as the incoming uniform is already present in the set,
/// the existing uniform will be replaced.
//--------------------------------------------------------------------------------------------------
void UniformSet::setUniform(Uniform* uniform)
{
    CVF_ASSERT(uniform);

    // Check if uniform is already in the set
    size_t numUniforms = m_uniforms.size();
    for (size_t i = 0; i < numUniforms; ++i)
    {
        if (System::strcmp(m_uniforms[i]->name(), uniform->name()) == 0)
        {
            if (m_uniforms[i] != uniform)
            {
                m_uniforms[i] = uniform;
            }

            return;
        }
    }

    m_uniforms.push_back(uniform);
}
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
std::vector< RigFemResultAddress> RigFemPartResultsCollection::getResAddrToComponentsToRead(const RigFemResultAddress& resVarAddr)
{
    std::map<std::string, std::vector<std::string> > fieldAndComponentNames;
    switch (resVarAddr.resultPosType)
    {
        case RIG_NODAL:
            fieldAndComponentNames = m_readerInterface->scalarNodeFieldAndComponentNames();
            break;
        case RIG_ELEMENT_NODAL:
            fieldAndComponentNames = m_readerInterface->scalarElementNodeFieldAndComponentNames();
            break;
        case RIG_INTEGRATION_POINT:
            fieldAndComponentNames = m_readerInterface->scalarIntegrationPointFieldAndComponentNames();
            break;
    }

    std::vector< RigFemResultAddress> resAddressToComponents;

    std::map<std::string, std::vector<std::string> >::iterator fcIt = fieldAndComponentNames.find(resVarAddr.fieldName);

    if (fcIt != fieldAndComponentNames.end())
    {
        std::vector<std::string> compNames = fcIt->second;
        if (resVarAddr.componentName != "") // If we did not request a particular component, do not add the components
        {
            for (size_t cIdx = 0; cIdx < compNames.size(); ++cIdx)
            {
                resAddressToComponents.push_back(RigFemResultAddress(resVarAddr.resultPosType, resVarAddr.fieldName, compNames[cIdx]));
            }
        }

        if (compNames.size() == 0) // This is a scalar field. Add one component named ""
        {
            CVF_ASSERT(resVarAddr.componentName == "");
            resAddressToComponents.push_back(resVarAddr);
        }
    }

    return resAddressToComponents;
}
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RicPasteEclipseViewsFeature::onActionTriggered(bool isChecked)
{
    PdmObjectHandle* destinationObject = dynamic_cast<PdmObjectHandle*>(SelectionManager::instance()->selectedItem());

    RimEclipseCase* eclipseCase = RicPasteFeatureImpl::findEclipseCase(destinationObject);
    assert(eclipseCase);

    PdmObjectGroup objectGroup;
    RicPasteFeatureImpl::findObjectsFromClipboardRefs(&objectGroup);

    if (objectGroup.objects.size() == 0) return;

    std::vector<caf::PdmPointer<RimEclipseView> > eclipseViews;
    objectGroup.objectsByType(&eclipseViews);

    // Add cases to case group
    for (size_t i = 0; i < eclipseViews.size(); i++)
    {
        RimEclipseView* rimReservoirView = dynamic_cast<RimEclipseView*>(eclipseViews[i]->xmlCapability()->copyByXmlSerialization(PdmDefaultObjectFactory::instance()));
        CVF_ASSERT(rimReservoirView);

        QString nameOfCopy = QString("Copy of ") + rimReservoirView->name;
        rimReservoirView->name = nameOfCopy;
        eclipseCase->reservoirViews().push_back(rimReservoirView);

        rimReservoirView->setEclipseCase(eclipseCase);

        // Resolve references after reservoir view has been inserted into Rim structures
        // Intersections referencing a well path/ simulation well requires this
        // TODO: initAfterReadRecursively can probably be removed
        rimReservoirView->initAfterReadRecursively();
        rimReservoirView->resolveReferencesRecursively();

        rimReservoirView->loadDataAndUpdate();

        caf::PdmDocument::updateUiIconStateRecursively(rimReservoirView);

        eclipseCase->updateConnectedEditors();
    }
}
Exemple #14
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
const RigFault* RigMainGrid::findFaultFromCellIndexAndCellFace(size_t reservoirCellIndex, cvf::StructGridInterface::FaceType face) const
{
    CVF_ASSERT(m_faultsPrCellAcc.notNull());

    if (face == cvf::StructGridInterface::NO_FACE) return NULL;

    int faultIdx = m_faultsPrCellAcc->faultIdx(reservoirCellIndex, face);
    if (faultIdx !=  RigFaultsPrCellAccumulator::NO_FAULT )
    {
        return m_faults.at(faultIdx);
    }

#if 0
    for (size_t i = 0; i < m_faults.size(); i++)
    {
        const RigFault* rigFault = m_faults.at(i);
        const std::vector<RigFault::FaultFace>& faultFaces = rigFault->faultFaces();

        for (size_t fIdx = 0; fIdx < faultFaces.size(); fIdx++)
        {
            if (faultFaces[fIdx].m_nativeReservoirCellIndex == cellIndex)
            {
                if (face == faultFaces[fIdx].m_nativeFace )
                {
                    return rigFault;
                }
            }

            if (faultFaces[fIdx].m_oppositeReservoirCellIndex == cellIndex)
            {
                if (face == cvf::StructGridInterface::oppositeFace(faultFaces[fIdx].m_nativeFace))
                {
                    return rigFault;
                }
            }
        }
    }
#endif
    return NULL;
}
Exemple #15
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RimGeoMechView::loadDataAndUpdate()
{
    caf::ProgressInfo progress(7, "");
    progress.setNextProgressIncrement(5);
    updateScaleTransform();

    if (m_geomechCase)
    {
        std::string errorMessage;
        if (!m_geomechCase->openGeoMechCase(&errorMessage))
        {
            QString displayMessage = errorMessage.empty() ? "Could not open the Odb file: \n" + m_geomechCase->caseFileName() : QString::fromStdString(errorMessage);

            QMessageBox::warning(RiuMainWindow::instance(), 
                            "File open error", 
                            displayMessage);
            m_geomechCase = NULL;
            return;
        }
    }
    progress.incrementProgress();

    progress.setProgressDescription("Reading Current Result");

    CVF_ASSERT(this->cellResult() != NULL);
    if (this->hasUserRequestedAnimation())
    {
        m_geomechCase->geoMechData()->femPartResults()->assertResultsLoaded(this->cellResult()->resultAddress());
    }
    progress.incrementProgress();
    progress.setProgressDescription("Create Display model");
   
    updateViewerWidget();

    this->geoMechPropertyFilterCollection()->loadAndInitializePropertyFilters();

    this->scheduleCreateDisplayModelAndRedraw();

    progress.incrementProgress();
}
Exemple #16
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
float RigFemPart::characteristicElementSize()
{
    if (m_characteristicElementSize != std::numeric_limits<float>::infinity()) return m_characteristicElementSize;

    // take 100 elements 
    float elmIdxJump = elementCount() / 100.0f;
    int elmIdxIncrement = elmIdxJump < 1 ? 1: (int) elmIdxJump;
    int elmsToAverageCount = 0;
    float sumMaxEdgeLength = 0;
    for (int elmIdx = 0; elmIdx < elementCount(); elmIdx += elmIdxIncrement)
    {
        RigElementType eType = this->elementType(elmIdx);

        if (eType == HEX8 || eType == HEX8P)
        {
            const int* elmentConn = this->connectivities(elmIdx);
            cvf::Vec3f nodePos0 = this->nodes().coordinates[elmentConn[0]];
            cvf::Vec3f nodePos1 = this->nodes().coordinates[elmentConn[1]];
            cvf::Vec3f nodePos3 = this->nodes().coordinates[elmentConn[3]];
            cvf::Vec3f nodePos4 = this->nodes().coordinates[elmentConn[4]];

            float l1 = (nodePos1-nodePos0).length();
            float l3 = (nodePos3-nodePos0).length();
            float l4 = (nodePos4-nodePos0).length();

            float maxLength = l1 > l3 ? l1: l3;
            maxLength = maxLength > l4 ? maxLength: l4;

            sumMaxEdgeLength += maxLength;
            ++elmsToAverageCount;
        }
    }

    CVF_ASSERT(elmsToAverageCount);

    m_characteristicElementSize = sumMaxEdgeLength/elmsToAverageCount;

    return m_characteristicElementSize;
}
Exemple #17
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
RimGeoMechView::RimGeoMechView(void)
{
    RiaApplication* app = RiaApplication::instance();
    RiaPreferences* preferences = app->preferences();
    CVF_ASSERT(preferences);

    CAF_PDM_InitObject("Geomechanical View", ":/ReservoirView.png", "", "");

    CAF_PDM_InitFieldNoDefault(&cellResult, "GridCellResult", "Color Result", ":/CellResult.png", "", "");
    cellResult = new RimGeoMechCellColors();
    cellResult.uiCapability()->setUiHidden(true);

    CAF_PDM_InitFieldNoDefault(&m_propertyFilterCollection, "PropertyFilters", "Property Filters", "", "", "");
    m_propertyFilterCollection = new RimGeoMechPropertyFilterCollection();
    m_propertyFilterCollection.uiCapability()->setUiHidden(true);

    //this->cellResult()->setReservoirView(this);
    this->cellResult()->legendConfig()->setReservoirView(this);

    m_scaleTransform = new cvf::Transform();
    m_vizLogic = new RivGeoMechVizLogic(this);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimValveTemplate* RicNewValveTemplateFeature::createNewValveTemplate()
{
    RimProject* project = RiaApplication::instance()->project();
    CVF_ASSERT(project);

    RimOilField* oilfield = project->activeOilField();
    if (oilfield == nullptr) return nullptr;

    RimValveTemplateCollection* valveTemplateColl = oilfield->valveTemplateCollection();

    if (valveTemplateColl)
    {
        RimValveTemplate* valveTemplate = new RimValveTemplate();
        QString           userLabel = QString("Valve Template #%1").arg(valveTemplateColl->valveTemplates().size() + 1);
        valveTemplate->setUserLabel(userLabel);
        valveTemplateColl->addValveTemplate(valveTemplate);
        valveTemplate->setUnitSystem(valveTemplateColl->defaultUnitSystemType());
        valveTemplate->setDefaultValuesFromUnits();
        return valveTemplate;
    }
    return nullptr;
}
Exemple #19
0
//--------------------------------------------------------------------------------------------------
/// Reads the property data requested into the \a reservoir, overwriting any previous 
/// properties with the same name.
//--------------------------------------------------------------------------------------------------
bool RifEclipseInputFileTools::readProperty(const QString& fileName, RigEclipseCaseData* caseData, const QString& eclipseKeyWord, const QString& resultName)
{
    CVF_ASSERT(caseData);

    if (!isValidDataKeyword(eclipseKeyWord)) return false;

    FILE* filePointer = util_fopen(fileName.toLatin1().data(), "r");
    if (!filePointer) return false;

    ecl_kw_type* eclipseKeywordData = ecl_kw_fscanf_alloc_grdecl_dynamic__(filePointer, eclipseKeyWord.toLatin1().data(), false, ecl_type_create_from_type(ECL_FLOAT_TYPE));
    bool isOk = false;
    if (eclipseKeywordData)
    {
        isOk = readDataFromKeyword(eclipseKeywordData, caseData, resultName);

        ecl_kw_free(eclipseKeywordData);
    }

    util_fclose(filePointer);

    return isOk;
}
Exemple #20
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void LocatorPanWalkRotate::updatePan(double tx, double ty)
{
    CVF_ASSERT(m_camera.notNull());

    // Viewport size in world coordinates
    const double aspect = m_camera->aspectRatio();
    const double vpWorldSizeY = m_camera->frontPlaneFrustumHeight();
    const double vpWorldSizeX = vpWorldSizeY*aspect;

    const Vec3d camUp = m_camera->up();
    const Vec3d camRight = m_camera->right();

    Camera::ProjectionType projType = m_camera->projection();
 
    if (projType == Camera::PERSPECTIVE)
    {
        // Compute distance from camera to point projected onto camera forward direction
        const Vec3d camPos = m_camera->position();
        const Vec3d camDir = m_camera->direction();
        const Vec3d vDiff = m_pos - camPos;
        const double camPointDist = Math::abs(camDir*vDiff);

        const double nearPlane = m_camera->nearPlane();
        Vec3d vX =  camRight*((tx*vpWorldSizeX)/nearPlane)*camPointDist;
        Vec3d vY =  camUp*((ty*vpWorldSizeY)/nearPlane)*camPointDist;
        
        Vec3d translation = vX + vY;
        m_pos += translation;
    }

    else if (projType == Camera::ORTHO)
    {
        Vec3d vX =  camRight*tx*vpWorldSizeX;
        Vec3d vY =  camUp*ty*vpWorldSizeY;

        Vec3d translation = vX + vY;
        m_pos += translation;
    }
}
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RicCopyIntersectionsToAllViewsInCaseFeature::copyIntersectionBoxesToOtherViews(RimCase& gridCase, std::vector<RimIntersectionBox*> intersectionBoxes)
{
    for (RimIntersectionBox* intersectionBox : intersectionBoxes)
    {
        for (Rim3dView* const view : gridCase.views())
        {
            RimGridView* currGridView = dynamic_cast<RimGridView*>(view);
            RimGridView* parentView = nullptr;
            intersectionBox->firstAncestorOrThisOfType(parentView);

            if (currGridView && parentView != nullptr && parentView != currGridView)
            {
                RimIntersectionCollection* destCollection = currGridView->crossSectionCollection();

                RimIntersectionBox* copy = dynamic_cast<RimIntersectionBox*>(intersectionBox->xmlCapability()->copyByXmlSerialization(caf::PdmDefaultObjectFactory::instance()));
                CVF_ASSERT(copy);

                destCollection->appendIntersectionBoxAndUpdate(copy);
            }
        }
    }
}
//--------------------------------------------------------------------------------------------------
/// Get set of Eclipse files based on an input file and its path
//--------------------------------------------------------------------------------------------------
bool RifEclipseOutputFileTools::findSiblingFilesWithSameBaseName(const QString& fullPathFileName, QStringList* baseNameFiles)
{
    CVF_ASSERT(baseNameFiles);
    baseNameFiles->clear();

    QString filePath = QFileInfo(fullPathFileName).absoluteFilePath();
    filePath = QFileInfo(filePath).path();
    QString fileNameBase = QFileInfo(fullPathFileName).completeBaseName();

    stringlist_type* eclipseFiles = stringlist_alloc_new();
    ecl_util_select_filelist(RiaStringEncodingTools::toNativeEncoded(filePath).data(), RiaStringEncodingTools::toNativeEncoded(fileNameBase).data(), ECL_OTHER_FILE, false, eclipseFiles);

    int i;
    for (i = 0; i < stringlist_get_size(eclipseFiles); i++)
    {
        baseNameFiles->append(RiaStringEncodingTools::fromNativeEncoded(stringlist_safe_iget(eclipseFiles, i)));
    }

    stringlist_free(eclipseFiles);

    return baseNameFiles->count() > 0;
}
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RimCellRangeFilter::setDefaultValues()
{
    CVF_ASSERT(m_parentContainer);

    RigGridBase* grid = selectedGrid();

    RigActiveCellInfo* actCellInfo = m_parentContainer->activeCellInfo();
    if (grid == m_parentContainer->mainGrid() && actCellInfo)
    {
        cvf::Vec3st min, max;
        actCellInfo->IJKBoundingBox(min, max);

        // Adjust to Eclipse indexing
        min.x() = min.x() + 1;
        min.y() = min.y() + 1;
        min.z() = min.z() + 1;

        max.x() = max.x() + 1;
        max.y() = max.y() + 1;
        max.z() = max.z() + 1;

        startIndexI = static_cast<int>(min.x());
        startIndexJ = static_cast<int>(min.y());
        startIndexK = static_cast<int>(min.z());
        cellCountI = static_cast<int>(max.x() - min.x() + 1);
        cellCountJ = static_cast<int>(max.y() - min.y() + 1);
        cellCountK = static_cast<int>(max.z() - min.z() + 1);
    }
    else
    {
        startIndexI = 1;
        startIndexJ = 1;
        startIndexK = 1;
        cellCountI = static_cast<int>(grid->cellCountI() );
        cellCountJ = static_cast<int>(grid->cellCountJ() );
        cellCountK = static_cast<int>(grid->cellCountK() );
    }
}
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RicPasteSummaryPlotFeature::copyPlotAndAddToCollection(RimSummaryPlot *sourcePlot)
{
    RimSummaryPlotCollection* plotColl = caf::firstAncestorOfTypeFromSelectedObject<RimSummaryPlotCollection*>();

    if (plotColl)
    {
        RimSummaryPlot* newSummaryPlot = dynamic_cast<RimSummaryPlot*>(sourcePlot->xmlCapability()->copyByXmlSerialization(caf::PdmDefaultObjectFactory::instance()));
        CVF_ASSERT(newSummaryPlot);

        plotColl->summaryPlots.push_back(newSummaryPlot);

        // Resolve references after object has been inserted into the data model
        newSummaryPlot->resolveReferencesRecursively();
        newSummaryPlot->initAfterReadRecursively();

        QString nameOfCopy = QString("Copy of ") + newSummaryPlot->description();
        newSummaryPlot->setDescription(nameOfCopy);

        plotColl->updateConnectedEditors();

        newSummaryPlot->loadDataAndUpdate();
    }
}
//--------------------------------------------------------------------------------------------------
/// Add one face 
/// 
/// The type of primitive added will be determined from the number of indices passed in \a indices
/// 
/// \remarks Currently, points and lines are not supported. Faces with more than 4 indices will
///          be triangulated using fanning
//--------------------------------------------------------------------------------------------------
void GeometryBuilder::addFace(const UIntArray& indices)
{
    size_t numIndices = indices.size();
    CVF_ASSERT(numIndices >= 3);

    if (numIndices == 3)
    {
        addTriangle(indices[0], indices[1], indices[2]);
    }
    else if (numIndices == 4)
    {
        addQuad(indices[0], indices[1], indices[2], indices[3]);
    }
    else
    {
        size_t numTriangles = numIndices - 2;
        size_t i;
        for (i = 0; i < numTriangles; i++)
        {
            addTriangle(indices[0], indices[i + 1], indices[i + 2]);
        }
    }
}
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RivTernaryTextureCoordsCreator::createTextureCoords(cvf::Vec2fArray* textureCoords, const std::vector<size_t>& triangleToCellIdx, const RigTernaryResultAccessor* resultAccessor, const RivTernaryResultToTextureMapper* texMapper)
{
    CVF_ASSERT(textureCoords && resultAccessor && texMapper);

    size_t numVertices = triangleToCellIdx.size() * 3;
    textureCoords->resize(numVertices);
    cvf::Vec2f* rawPtr = textureCoords->ptr();

#pragma omp parallel for
    for (int i = 0; i < static_cast<int>(triangleToCellIdx.size()); i++)
    {
        size_t cellIdx = triangleToCellIdx[i];

        cvf::Vec2d resultValue = resultAccessor->cellScalarGlobIdx(cellIdx);
        cvf::Vec2f texCoord = texMapper->getTexCoord(resultValue.x(), resultValue.y(), cellIdx);

        size_t j;
        for (j = 0; j < 3; j++)
        {
            rawPtr[i * 3 + j] = texCoord;
        }
    }
}
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void CategoryMapper::setInterpolateColors(const cvf::Color3ubArray& colorArray)
{
    CVF_ASSERT(colorArray.size());

    if (m_categoryValues.size() > 1 && colorArray.size() > 1)
    {
        m_colors = *interpolateColorArray(colorArray, static_cast<cvf::uint>(m_categoryValues.size()));

        recomputeMaxTexCoord();
        return;
    }

    // Either we are requesting one output color, or we have only one input color

    m_colors.clear();
    m_colors.reserve(m_categoryValues.size());
    for (size_t cIdx = 0;  cIdx < m_categoryValues.size(); ++cIdx)
    {
        m_colors.add(colorArray[0]);
    }

    recomputeMaxTexCoord();
}
Exemple #28
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
RimGeoMechCase::~RimGeoMechCase(void)
{
    geoMechViews.deleteAllChildObjects();

    RimProject* project = RiaApplication::instance()->project();
    if (project)
    {
        if (project->mainPlotCollection())
        {
            RimWellLogPlotCollection* plotCollection = project->mainPlotCollection()->wellLogPlotCollection();
            if (plotCollection)
            {
                plotCollection->removeExtractors(this->geoMechData());
            }
        }
    }

    if (this->geoMechData())
    {
        // At this point, we assume that memory should be released
        CVF_ASSERT(this->geoMechData()->refCount() == 1);
    }
}
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RimCellPropertyFilter::computeResultValueRange()
{
    CVF_ASSERT(m_parentContainer);

    double min = 0.0;
    double max = 0.0;

    size_t scalarIndex = resultDefinition->scalarResultIndex();
    if (scalarIndex != cvf::UNDEFINED_SIZE_T)
    {
        RimReservoirCellResultsStorage* results = resultDefinition->currentGridCellResults();
        if (results)
        {
            results->cellResults()->minMaxCellScalarValues(scalarIndex, min, max);
        }
    }

    m_maximumResultValue = max;
    m_minimumResultValue = min;

    lowerBound.setUiName(QString("Min (%1)").arg(min));
    upperBound.setUiName(QString("Max (%1)").arg(max));
}
//--------------------------------------------------------------------------------------------------
/// Restart timer and laptime
//--------------------------------------------------------------------------------------------------
void Timer::restart()
{
    CVF_ASSERT(m_timerState);

#ifdef WIN32

    LARGE_INTEGER tick;
    QueryPerformanceCounter(&tick);
    m_timerState->m_startTick = tick.QuadPart;
    m_timerState->m_lastLapTick = m_timerState->m_startTick;

#elif defined(CVF_LINUX) || defined(CVF_ANDROID)

    clock_gettime(CLOCK_MONOTONIC, &m_timerState->m_timeStart);
    m_timerState->m_timeMark = m_timerState->m_timeStart;

#elif defined(CVF_IOS) || defined(CVF_OSX)

    m_timerState->m_startTime = mach_absolute_time();
    m_timerState->m_lastLapTime   = m_timerState->m_startTime;

#endif
}