DLLEXPORT void vclSet(const int n, const ScalarType alpha, ScalarType y[], const int yOffset) { auto yPtr = &(y[0]) + yOffset; viennacl::vector<ScalarType> yVec(yPtr, viennacl::MAIN_MEMORY, n); viennacl::linalg::vector_assign(yVec, alpha); };
DLLEXPORT void vclAddScalar(const int n, const ScalarType alpha, ScalarType y[], const int yOffset) { auto yPtr = &(y[0]) + yOffset; viennacl::vector<ScalarType> yVec(yPtr, viennacl::MAIN_MEMORY, n); viennacl::vector<ScalarType> scalarVec ( viennacl::scalar_vector<ScalarType>(n, alpha) ); yVec += scalarVec; };
DLLEXPORT void vclScale(const int n, const ScalarType alpha, const ScalarType x[], const int xOffset, ScalarType y[], const int yOffset) { auto xPtr = &(x[0]) + xOffset; auto yPtr = &(y[0]) + yOffset; viennacl::vector<ScalarType> xVec((ScalarType*)xPtr, viennacl::MAIN_MEMORY, n); viennacl::vector<ScalarType> yVec((ScalarType*)yPtr, viennacl::MAIN_MEMORY, n); yVec = xVec * alpha; };
DLLEXPORT ScalarType vclDot(const int n, const ScalarType x[], const int xOffset, const ScalarType y[], const int yOffset) { auto xPtr = &(x[0]) + xOffset; auto yPtr = &(y[0]) + yOffset; viennacl::vector<ScalarType> xVec((ScalarType*)xPtr, viennacl::MAIN_MEMORY, n); viennacl::vector<ScalarType> yVec((ScalarType*)yPtr, viennacl::MAIN_MEMORY, n); return viennacl::linalg::inner_prod(xVec, yVec); };
DLLEXPORT ScalarType vclDotEx(const ScalarType x[], const int xOffset, const int xLength, const int incx, const ScalarType y[], const int yOffset, const int yLength, const int incy) { auto xPtr = &(x[0]) + xOffset; auto yPtr = &(y[0]) + yOffset; viennacl::vector<ScalarType> xVec((ScalarType*)xPtr, viennacl::MAIN_MEMORY, xLength); viennacl::vector<ScalarType> yVec((ScalarType*)yPtr, viennacl::MAIN_MEMORY, yLength); return 0; };
DLLEXPORT void vclAxpby(const int n, const ScalarType alpha, const ScalarType x[], const int xOffset, ScalarType beta, ScalarType y[], const int yOffset) { auto xPtr = &(x[0]) + xOffset; auto yPtr = &(y[0]) + yOffset; // wrap host buffer within ViennaCL vectors: viennacl::vector<ScalarType> xVec((ScalarType*)xPtr, viennacl::MAIN_MEMORY, n); viennacl::vector<ScalarType> yVec(yPtr, viennacl::MAIN_MEMORY, n); viennacl::linalg::avbv(yVec, xVec, alpha, n, false, false, yVec, beta, n, false, false); };
void DiscreteBoundaryOperator<ValueType>::applyImpl( const Thyra::EOpTransp M_trans, const Thyra::MultiVectorBase<ValueType> &X_in, const Teuchos::Ptr<Thyra::MultiVectorBase<ValueType>> &Y_inout, const ValueType alpha, const ValueType beta) const { typedef Thyra::Ordinal Ordinal; // Note: the name is VERY misleading: these asserts don't disappear in // release runs, and in case of failure throw exceptions rather than // abort. TEUCHOS_ASSERT(this->opSupported(M_trans)); TEUCHOS_ASSERT(X_in.range()->isCompatible(*this->domain())); TEUCHOS_ASSERT(Y_inout->range()->isCompatible(*this->range())); TEUCHOS_ASSERT(Y_inout->domain()->isCompatible(*X_in.domain())); const Ordinal colCount = X_in.domain()->dim(); // Loop over the input columns for (Ordinal col = 0; col < colCount; ++col) { // Get access the the elements of X_in's and Y_inout's column #col Thyra::ConstDetachedSpmdVectorView<ValueType> xVec(X_in.col(col)); Thyra::DetachedSpmdVectorView<ValueType> yVec(Y_inout->col(col)); const Teuchos::ArrayRCP<const ValueType> xArray(xVec.sv().values()); const Teuchos::ArrayRCP<ValueType> yArray(yVec.sv().values()); // Wrap the Trilinos array in an Armadillo vector. const_cast is used // because it's more natural to have a const arma::Col<ValueType> array // than an arma::Col<const ValueType> one. const arma::Col<ValueType> xCol(const_cast<ValueType *>(xArray.get()), xArray.size(), false /* copy_aux_mem */); arma::Col<ValueType> yCol(yArray.get(), yArray.size(), false); applyBuiltInImpl(static_cast<TranspositionMode>(M_trans), xCol, yCol, alpha, beta); } }
int PointFloatShapeFeatureExtractor::extractFeatures(const LTKTraceGroup& inTraceGroup, vector<LTKShapeFeaturePtr>& outFeatureVec) { LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << "Entering " << "PointFloatShapeFeatureExtractor::extractFeatures()" << endl; PointFloatShapeFeature *featurePtr = NULL; float x,y,deltax; int numPoints=0; // number of pts int count=0; int currentStrokeSize; float sintheta, costheta,sqsum; int i; int numberOfTraces = inTraceGroup.getNumTraces(); if (numberOfTraces == 0 ) { LOG( LTKLogger::LTK_LOGLEVEL_ERR) << "Error: " << EEMPTY_TRACE_GROUP << " : " << getErrorMessage(EEMPTY_TRACE_GROUP)<< " PointFloatShapeFeatureExtractor::extractFeatures" <<endl; LTKReturnError(EEMPTY_TRACE_GROUP); } LTKTraceVector allTraces = inTraceGroup.getAllTraces(); LTKTraceVector::iterator traceIter = allTraces.begin(); LTKTraceVector::iterator traceEnd = allTraces.end(); //***CONCATENTATING THE STROKES*** for (; traceIter != traceEnd ; ++traceIter) { floatVector tempxVec, tempyVec; (*traceIter).getChannelValues("X", tempxVec); (*traceIter).getChannelValues("Y", tempyVec); // Number of points in the stroke numPoints = numPoints + tempxVec.size(); } //***THE CONCATENATED FULL STROKE*** floatVector xVec(numPoints); floatVector yVec(numPoints); traceIter = allTraces.begin(); traceEnd = allTraces.end(); boolVector penUp; // Add the penUp here for (; traceIter != traceEnd ; ++traceIter) { floatVector tempxVec, tempyVec; (*traceIter).getChannelValues("X", tempxVec); (*traceIter).getChannelValues("Y", tempyVec); currentStrokeSize = tempxVec.size(); if (currentStrokeSize == 0) { LOG( LTKLogger::LTK_LOGLEVEL_ERR) << "Error: " << EEMPTY_TRACE << " : " << getErrorMessage(EEMPTY_TRACE) << " PointFloatShapeFeatureExtractor::extractFeatures" <<endl; LTKReturnError(EEMPTY_TRACE); } for( int point=0; point < currentStrokeSize ; point++ ) { xVec[count] = tempxVec[point]; yVec[count] = tempyVec[point]; count++; if(point == currentStrokeSize - 1 ) { penUp.push_back(true); } else { penUp.push_back(false); } } } //***CONCATENTATING THE STROKES*** vector<float> theta(numPoints); vector<float> delta_x(numPoints-1); vector<float> delta_y(numPoints-1); for(i=0; i<numPoints-1; ++i) { delta_x[i]=xVec[i+1]-xVec[i]; delta_y[i]=yVec[i+1]-yVec[i]; } //Add the controlInfo here sqsum = sqrt( pow(xVec[0],2)+ pow(yVec[0],2))+ EPS; sintheta = (1+yVec[0]/sqsum)*PREPROC_DEF_NORMALIZEDSIZE/2; costheta = (1+xVec[0]/sqsum)*PREPROC_DEF_NORMALIZEDSIZE/2; featurePtr = new PointFloatShapeFeature(xVec[0], yVec[0], sintheta, costheta, penUp[0]); outFeatureVec.push_back(LTKShapeFeaturePtr(featurePtr)); featurePtr = NULL; for( i=1; i<numPoints; ++i) { //Add the controlInfo here sqsum = sqrt(pow(delta_x[i-1],2) + pow(delta_y[i-1],2))+EPS; sintheta = (1+delta_y[i-1]/sqsum)*PREPROC_DEF_NORMALIZEDSIZE/2; costheta = (1+delta_x[i-1]/sqsum)*PREPROC_DEF_NORMALIZEDSIZE/2; featurePtr = new PointFloatShapeFeature(xVec[i], yVec[i], sintheta, costheta, penUp[i]); //***POPULATING THE FEATURE VECTOR*** outFeatureVec.push_back(LTKShapeFeaturePtr(featurePtr)); featurePtr = NULL; } LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << "Exiting " << "PointFloatShapeFeatureExtractor::extractFeatures()" << endl; return SUCCESS; }
//////////////////////////////////////// // PUBLIC UTILITY FUNCTIONS //////////////////////////////////////// void Camera::Render() { D3DXVECTOR3 up, position, lookAt; float yaw, pitch, roll; D3DXMATRIX rotationMatrix; D3DXMatrixIdentity(&rotationMatrix); // Setup the vector that points upwards. up.x = 0.0f; up.y = 1.0f; up.z = 0.0f; // Setup the position of the camera in the world. position.x = m_positionX; position.y = m_positionY; position.z = m_positionZ; // Setup where the camera is looking by default. lookAt.x = 0.0f; lookAt.y = 0.0f; lookAt.z = 1.0f; // Set the yaw (Y axis), pitch (X axis), and roll (Z axis) rotations in radians. pitch = m_rotationX * 0.0174532925f; yaw = m_rotationY * 0.0174532925f; roll = m_rotationZ * 0.0174532925f; // Create the rotation matrix from the yaw, pitch, and roll values. D3DXMatrixRotationYawPitchRoll(&rotationMatrix, yaw, pitch, roll); // Move position based on local X/Y/Z vectors D3DXVECTOR3 xVec(rotationMatrix._11,rotationMatrix._12,rotationMatrix._13); D3DXVECTOR3 yVec(rotationMatrix._21,rotationMatrix._22,rotationMatrix._23); D3DXVECTOR3 zVec(rotationMatrix._31,rotationMatrix._32,rotationMatrix._33); // Get amount to add to position D3DXVec3Scale(&xVec,&xVec,m_moveDelta.x); D3DXVec3Scale(&yVec,&yVec,m_moveDelta.y); D3DXVec3Scale(&zVec,&zVec,m_moveDelta.z); // Autobots: roll out! position += xVec + yVec + zVec; // Save new position m_positionX = position.x; m_positionY = position.y; m_positionZ = position.z; // Transform the lookAt and up vector by the rotation matrix so the view is correctly rotated at the origin. D3DXVec3TransformCoord(&lookAt, &lookAt, &rotationMatrix); D3DXVec3TransformCoord(&up, &up, &rotationMatrix); // Translate the rotated camera position to the location of the viewer. lookAt = position + lookAt; // Finally create the view matrix from the three updated vectors. D3DXMatrixLookAtLH(&m_viewMatrix, &position, &lookAt, &up); return; }