Ejemplo n.º 1
0
 def mouseMoveEvent(self, event):
     if self._lastMousePos is not None:
         pos = [ event.x(), event.y() ]
         delta = [ pos[0] - self._lastMousePos[0], pos[1] - self._lastMousePos[1] ]
         result, eye = self._sceneviewer.getEyePosition()
         result, lookat = self._sceneviewer.getLookatPosition()
         result, up = self._sceneviewer.getUpVector()
         lookatToEye = vectorops.sub(eye, lookat)
         eyeDistance = vectorops.magnitude(lookatToEye)
         front = vectorops.div(lookatToEye, eyeDistance)
         right = vectorops.cross(up, front)
         if self._active_button == QtCore.Qt.LeftButton:
             mag = vectorops.magnitude(delta)
             prop = vectorops.div(delta, mag)
             axis = vectorops.add(vectorops.mult(up, prop[0]), vectorops.mult(right, prop[1]))
             angle = mag*0.002
             self._model.rotateModel(axis, angle)
         elif self._active_button == QtCore.Qt.MiddleButton:
             result, l, r, b, t, near, far = self._sceneviewer.getViewingVolume()
             viewportWidth = self.width()
             viewportHeight = self.height()
             if viewportWidth > viewportHeight:
                 eyeScale = (t - b) / viewportHeight
             else:
                 eyeScale = (r - l) / viewportWidth
             offset = vectorops.add(vectorops.mult(right, eyeScale*delta[0]), vectorops.mult(up, -eyeScale*delta[1]))
             self._model.translateModel(offset)
         elif self._active_button == QtCore.Qt.RightButton:
             factor = 1.0 + delta[1]*0.0005
             if factor < 0.9:
                 factor = 0.9
             self._model.scaleModel(factor)
         self._lastMousePos = pos
     else:
         super(AlignmentSceneviewerWidget, self).mouseMoveEvent(event)
 def mouseMoveEvent(self, event):
     if self._lastMousePos is not None:
         pos = [ event.x(), event.y() ]
         delta = [ pos[0] - self._lastMousePos[0], pos[1] - self._lastMousePos[1] ]
         result, eye = self._sceneviewer.getEyePosition()
         result, lookat = self._sceneviewer.getLookatPosition()
         result, up = self._sceneviewer.getUpVector()
         lookatToEye = vectorops.sub(eye, lookat)
         eyeDistance = vectorops.magnitude(lookatToEye)
         front = vectorops.div(lookatToEye, eyeDistance)
         right = vectorops.cross(up, front)
         if self._active_button == QtCore.Qt.LeftButton:
             mag = vectorops.magnitude(delta)
             prop = vectorops.div(delta, mag)
             axis = vectorops.add(vectorops.mult(up, prop[0]), vectorops.mult(right, prop[1]))
             angle = mag*0.002
             self._model.rotateModel(axis, angle)
         elif self._active_button == QtCore.Qt.MiddleButton:
             result, l, r, b, t, near, far = self._sceneviewer.getViewingVolume()
             viewportWidth = self.width()
             viewportHeight = self.height()
             if viewportWidth > viewportHeight:
                 eyeScale = (t - b) / viewportHeight
             else:
                 eyeScale = (r - l) / viewportWidth
             offset = vectorops.add(vectorops.mult(right, eyeScale*delta[0]), vectorops.mult(up, -eyeScale*delta[1]))
             self._model.offsetModel(offset)
         elif self._active_button == QtCore.Qt.RightButton:
             factor = 1.0 + delta[1]*0.0005
             if factor < 0.9:
                 factor = 0.9
             self._model.scaleModel(factor)
         self._lastMousePos = pos
     else:
         super(AlignmentSceneviewerWidget, self).mouseMoveEvent(event)
    def filterNonNormal(self):
        if self._storedMeshLocationField is None:
            print("Can't filter until projections are done")
            return
        fm = self._region.getFieldmodule()
        cache = fm.createFieldcache()
        result, maxError = self._dataProjectionMaximumErrorField.evaluateReal(
            cache, 1)
        if result != ZINC_OK:
            print("Can't filter non-normal as can't evaluate max error: " +
                  result)
            return
        if maxError <= 0:
            print("Can't filter non-normal as max error = " + maxError)
            return
        fm.beginChange()

        # don't filter points with tiny errors relative to model range
        minimums, maximums = self._getModelRange()
        scale = vectorops.magnitude(vectorops.sub(maximums, minimums))
        errorLimit = 0.0001 * scale
        errorLimit = maxError * 0.001
        errorLimitField = fm.createFieldConstant([errorLimit])
        errorGreaterThanLimitField = fm.createFieldGreaterThan(
            self._dataProjectionErrorField, errorLimitField)

        deriv1 = fm.createFieldDerivative(self._modelCoordinateField, 1)
        deriv2 = fm.createFieldDerivative(self._modelCoordinateField, 2)
        cp = fm.createFieldCrossProduct(deriv1, deriv2)
        normalField = fm.createFieldNormalise(cp)
        dataNormalField = fm.createFieldEmbedded(normalField,
                                                 self._storedMeshLocationField)

        normalProjectionLimit = fm.createFieldConstant(
            [self._filterNonNormalProjectionLimit])
        normalisedProjection = fm.createFieldNormalise(
            self._dataProjectionDeltaCoordinateField)
        normalAlignment = fm.createFieldDotProduct(normalisedProjection,
                                                   dataNormalField)
        absNormalAlignment = fm.createFieldAbs(normalAlignment)
        isNonNormalField = fm.createFieldLessThan(absNormalAlignment,
                                                  normalProjectionLimit)

        falseField = fm.createFieldConstant([0])
        conditionalField = fm.createFieldIf(errorGreaterThanLimitField,
                                            isNonNormalField, falseField)

        activeDatapointsGroup = self._activeDataPointGroupField.getNodesetGroup(
        )
        result = activeDatapointsGroup.removeNodesConditional(conditionalField)
        fm.endChange()

        self._autorangeSpectrum()
    def filterNonNormal(self):
        if self._storedMeshLocationField is None:
            print("Can't filter until projections are done")
            return
        fm = self._region.getFieldmodule()
        cache = fm.createFieldcache()
        result, maxError = self._dataProjectionMaximumErrorField.evaluateReal(cache, 1)
        if result != ZINC_OK:
            print("Can't filter non-normal as can't evaluate max error: " + result)
            return
        if maxError <= 0:
            print("Can't filter non-normal as max error = " + maxError)
            return
        fm.beginChange()

        # don't filter points with tiny errors relative to model range
        minimums, maximums = self._getModelRange()
        scale = vectorops.magnitude(vectorops.sub(maximums, minimums))
        errorLimit = 0.0001*scale
        errorLimit = maxError*0.001
        errorLimitField = fm.createFieldConstant([errorLimit])
        errorGreaterThanLimitField = fm.createFieldGreaterThan(self._dataProjectionErrorField, errorLimitField)

        deriv1 = fm.createFieldDerivative(self._modelCoordinateField, 1)
        deriv2 = fm.createFieldDerivative(self._modelCoordinateField, 2)
        cp = fm.createFieldCrossProduct(deriv1, deriv2)
        normalField = fm.createFieldNormalise(cp)
        dataNormalField = fm.createFieldEmbedded(normalField, self._storedMeshLocationField)

        normalProjectionLimit = fm.createFieldConstant([self._filterNonNormalProjectionLimit])
        normalisedProjection = fm.createFieldNormalise(self._dataProjectionDeltaCoordinateField)
        normalAlignment = fm.createFieldDotProduct(normalisedProjection, dataNormalField)
        absNormalAlignment = fm.createFieldAbs(normalAlignment)
        isNonNormalField = fm.createFieldLessThan(absNormalAlignment, normalProjectionLimit)

        falseField = fm.createFieldConstant([0])
        conditionalField = fm.createFieldIf(errorGreaterThanLimitField, isNonNormalField, falseField)

        activeDatapointsGroup = self._activeDataPointGroupField.getNodesetGroup()
        result = activeDatapointsGroup.removeNodesConditional(conditionalField)
        fm.endChange()

        self._autorangeSpectrum()
 def _getAutoPointSize(self):
     minimums, maximums = self._getDataRange()
     dataSize = vectorops.magnitude(vectorops.sub(maximums, minimums))
     return 0.005 * dataSize
 def autoCentreModelOnData(self):
     minimums, maximums = self._getDataRange()
     dataCentre = vectorops.mult(vectorops.add(minimums, maximums), 0.5)
     self.setAlignOffset(vectorops.sub(dataCentre, self._modelCentre))
 def _getAutoPointSize(self):
     minimums, maximums = self._getDataRange()
     dataSize = vectorops.magnitude(vectorops.sub(maximums, minimums))
     return 0.005*dataSize
 def autoCentreModelOnData(self):
     minimums, maximums = self._getDataRange()
     dataCentre = vectorops.mult(vectorops.add(minimums, maximums), 0.5)
     self.setAlignOffset(vectorops.sub(dataCentre, self._modelCentre))