bool AffineInteractor3D ::ExecuteAction( Action *action, StateEvent const *stateEvent ) { bool ok = false; // Get data object BaseData *data = m_DataNode->GetData(); if ( data == NULL ) { MITK_ERROR << "No data object present!"; return ok; } // Get Event and extract renderer const Event *event = stateEvent->GetEvent(); BaseRenderer *renderer = NULL; vtkRenderWindow *renderWindow = NULL; vtkRenderWindowInteractor *renderWindowInteractor = NULL; vtkRenderer *currentVtkRenderer = NULL; vtkCamera *camera = NULL; if ( event != NULL ) { renderer = event->GetSender(); if ( renderer != NULL ) { renderWindow = renderer->GetRenderWindow(); if ( renderWindow != NULL ) { renderWindowInteractor = renderWindow->GetInteractor(); if ( renderWindowInteractor != NULL ) { currentVtkRenderer = renderWindowInteractor ->GetInteractorStyle()->GetCurrentRenderer(); if ( currentVtkRenderer != NULL ) { camera = currentVtkRenderer->GetActiveCamera(); } } } } } // Check if we have a DisplayPositionEvent const DisplayPositionEvent *dpe = dynamic_cast< const DisplayPositionEvent * >( stateEvent->GetEvent() ); if ( dpe != NULL ) { m_CurrentPickedPoint = dpe->GetWorldPosition(); m_CurrentPickedDisplayPoint = dpe->GetDisplayPosition(); } // Get the timestep to also support 3D+t int timeStep = 0; ScalarType timeInMS = 0.0; if ( renderer != NULL ) { timeStep = renderer->GetTimeStep( data ); timeInMS = renderer->GetTime(); } // If data is an mitk::Surface, extract it Surface *surface = dynamic_cast< Surface * >( data ); vtkPolyData *polyData = NULL; if ( surface != NULL ) { polyData = surface->GetVtkPolyData( timeStep ); // Extract surface normal from surface (if existent, otherwise use default) vtkPointData *pointData = polyData->GetPointData(); if ( pointData != NULL ) { vtkDataArray *normal = polyData->GetPointData()->GetVectors( "planeNormal" ); if ( normal != NULL ) { m_ObjectNormal[0] = normal->GetComponent( 0, 0 ); m_ObjectNormal[1] = normal->GetComponent( 0, 1 ); m_ObjectNormal[2] = normal->GetComponent( 0, 2 ); } } } // Get geometry object m_Geometry = data->GetGeometry( timeStep ); // Make sure that the data (if time-resolved) has enough entries; // if not, create the required extra ones (empty) data->Expand( timeStep+1 ); switch (action->GetActionId()) { case AcDONOTHING: ok = true; break; case AcCHECKOBJECT: { // Re-enable VTK interactor (may have been disabled previously) if ( renderWindowInteractor != NULL ) { renderWindowInteractor->Enable(); } // Check if we have a DisplayPositionEvent const DisplayPositionEvent *dpe = dynamic_cast< const DisplayPositionEvent * >( stateEvent->GetEvent() ); if ( dpe == NULL ) { ok = true; break; } // Check if an object is present at the current mouse position DataNode *pickedNode = dpe->GetPickedObjectNode(); StateEvent *newStateEvent; if ( pickedNode == m_DataNode ) { // Yes: object will be selected newStateEvent = new StateEvent( EIDYES ); } else { // No: back to start state newStateEvent = new StateEvent( EIDNO ); } this->HandleEvent( newStateEvent ); ok = true; break; } case AcDESELECTOBJECT: { // Color object white m_DataNode->SetColor( 1.0, 1.0, 1.0 ); RenderingManager::GetInstance()->RequestUpdateAll(); // Colorize surface / wireframe as inactive this->ColorizeSurface( polyData, m_CurrentPickedPoint, -1.0 ); ok = true; break; } case AcSELECTPICKEDOBJECT: { // Color object red m_DataNode->SetColor( 1.0, 0.0, 0.0 ); RenderingManager::GetInstance()->RequestUpdateAll(); // Colorize surface / wireframe dependend on distance from picked point this->ColorizeSurface( polyData, m_CurrentPickedPoint, 0.0 ); ok = true; break; } case AcINITMOVE: { // Disable VTK interactor until MITK interaction has been completed if ( renderWindowInteractor != NULL ) { renderWindowInteractor->Disable(); } // Check if we have a DisplayPositionEvent const DisplayPositionEvent *dpe = dynamic_cast< const DisplayPositionEvent * >( stateEvent->GetEvent() ); if ( dpe == NULL ) { ok = true; break; } //DataNode *pickedNode = dpe->GetPickedObjectNode(); m_InitialPickedPoint = m_CurrentPickedPoint; m_InitialPickedDisplayPoint = m_CurrentPickedDisplayPoint; if ( currentVtkRenderer != NULL ) { vtkInteractorObserver::ComputeDisplayToWorld( currentVtkRenderer, m_InitialPickedDisplayPoint[0], m_InitialPickedDisplayPoint[1], 0.0, //m_InitialInteractionPickedPoint[2], m_InitialPickedPointWorld ); } // Make deep copy of current Geometry3D of the plane data->UpdateOutputInformation(); // make sure that the Geometry is up-to-date m_OriginalGeometry = static_cast< Geometry3D * >( data->GetGeometry( timeStep )->Clone().GetPointer() ); ok = true; break; } case AcMOVE: { // Check if we have a DisplayPositionEvent const DisplayPositionEvent *dpe = dynamic_cast< const DisplayPositionEvent * >( stateEvent->GetEvent() ); if ( dpe == NULL ) { ok = true; break; } if ( currentVtkRenderer != NULL ) { vtkInteractorObserver::ComputeDisplayToWorld( currentVtkRenderer, m_CurrentPickedDisplayPoint[0], m_CurrentPickedDisplayPoint[1], 0.0, //m_InitialInteractionPickedPoint[2], m_CurrentPickedPointWorld ); } Vector3D interactionMove; interactionMove[0] = m_CurrentPickedPointWorld[0] - m_InitialPickedPointWorld[0]; interactionMove[1] = m_CurrentPickedPointWorld[1] - m_InitialPickedPointWorld[1]; interactionMove[2] = m_CurrentPickedPointWorld[2] - m_InitialPickedPointWorld[2]; if ( m_InteractionMode == INTERACTION_MODE_TRANSLATION ) { Point3D origin = m_OriginalGeometry->GetOrigin(); Vector3D transformedObjectNormal; data->GetGeometry( timeStep )->IndexToWorld( m_ObjectNormal, transformedObjectNormal ); data->GetGeometry( timeStep )->SetOrigin( origin + transformedObjectNormal * (interactionMove * transformedObjectNormal) ); } else if ( m_InteractionMode == INTERACTION_MODE_ROTATION ) { if ( camera ) { double vpn[3]; camera->GetViewPlaneNormal( vpn ); Vector3D viewPlaneNormal; viewPlaneNormal[0] = vpn[0]; viewPlaneNormal[1] = vpn[1]; viewPlaneNormal[2] = vpn[2]; Vector3D rotationAxis = itk::CrossProduct( viewPlaneNormal, interactionMove ); rotationAxis.Normalize(); int *size = currentVtkRenderer->GetSize(); double l2 = (m_CurrentPickedDisplayPoint[0] - m_InitialPickedDisplayPoint[0]) * (m_CurrentPickedDisplayPoint[0] - m_InitialPickedDisplayPoint[0]) + (m_CurrentPickedDisplayPoint[1] - m_InitialPickedDisplayPoint[1]) * (m_CurrentPickedDisplayPoint[1] - m_InitialPickedDisplayPoint[1]); double rotationAngle = 360.0 * sqrt(l2/(size[0]*size[0]+size[1]*size[1])); // Use center of data bounding box as center of rotation Point3D rotationCenter = m_OriginalGeometry->GetCenter();; // Reset current Geometry3D to original state (pre-interaction) and // apply rotation RotationOperation op( OpROTATE, rotationCenter, rotationAxis, rotationAngle ); Geometry3D::Pointer newGeometry = static_cast< Geometry3D * >( m_OriginalGeometry->Clone().GetPointer() ); newGeometry->ExecuteOperation( &op ); data->SetClonedGeometry(newGeometry, timeStep); } } RenderingManager::GetInstance()->RequestUpdateAll(); ok = true; break; } default: return Superclass::ExecuteAction( action, stateEvent ); } return ok; }
DWORD WINAPI Classify_Data2(LPVOID lpParamter) { OneMinute oneninute; BaseData *base; base= &oneninute; bool flag = false; //每次只处理一个数据 while(1) { if(method_Rest_Time()) { Sleep(1000); //在休盘时间重置 清除内存中数据 /**********要改的地方**********/ if (oneninute.tsmd_a->size()!=0) { oneninute.TIME_INTERVAL=0; oneninute.contract=""; oneninute.compare_time=0; memset(&(oneninute.current_data),0,sizeof(oneninute.current_data)); memset(&(oneninute.compare_data),0,sizeof(oneninute.compare_data)); oneninute.tsmd_a = NULL; oneninute.tsmd_a= new map<string,OneMinute*>(); base = NULL; base = &oneninute; } } //进入临界区 EnterCriticalSection(&cs); CThostFtdcDepthMarketDataField_Custom* dd =cmdSpi_custom->methodGetDatas_After(); //释放临界区 LeaveCriticalSection(&cs); if (dd!=NULL) { flag = true; } if (flag) { flag = false; //转换数据 CThostFtdcDepthMarketDataField_Custom_Tick ct = methodChangeData(*dd); if (!base->isExist((string)(ct.InstrumentID))) { base->addContractToMap(&ct); } else { base->updateData(&ct); } }//end flag }//end while }//end Classify_Data2
namespace cocostudio { AffineTransform TransformHelp::helpMatrix1; AffineTransform TransformHelp::helpMatrix2; Vec2 TransformHelp::helpPoint1; Vec2 TransformHelp::helpPoint2; BaseData helpParentNode; TransformHelp::TransformHelp() { } void TransformHelp::transformFromParent(BaseData &node, const BaseData &parentNode) { nodeToMatrix(node, helpMatrix1); nodeToMatrix(parentNode, helpMatrix2); helpMatrix2 = AffineTransformInvert(helpMatrix2); helpMatrix1 = AffineTransformConcat(helpMatrix1, helpMatrix2); matrixToNode(helpMatrix1, node); } void TransformHelp::transformToParent(BaseData &node, const BaseData &parentNode) { nodeToMatrix(node, helpMatrix1); nodeToMatrix(parentNode, helpMatrix2); helpMatrix1 = AffineTransformConcat(helpMatrix1, helpMatrix2); matrixToNode(helpMatrix1, node); } void TransformHelp::transformFromParentWithoutScale(BaseData &node, const BaseData &parentNode) { helpParentNode.copy(&parentNode); helpParentNode.scaleX = 1; helpParentNode.scaleY = 1; nodeToMatrix(node, helpMatrix1); nodeToMatrix(helpParentNode, helpMatrix2); helpMatrix2 = AffineTransformInvert(helpMatrix2); helpMatrix1 = AffineTransformConcat(helpMatrix1, helpMatrix2); matrixToNode(helpMatrix1, node); } void TransformHelp::transformToParentWithoutScale(BaseData &node, const BaseData &parentNode) { helpParentNode.copy(&parentNode); helpParentNode.scaleX = 1; helpParentNode.scaleY = 1; nodeToMatrix(node, helpMatrix1); nodeToMatrix(helpParentNode, helpMatrix2); helpMatrix1 = AffineTransformConcat(helpMatrix1, helpMatrix2); matrixToNode(helpMatrix1, node); } void TransformHelp::nodeToMatrix(const BaseData &node, AffineTransform &matrix) { if (node.skewX == -node.skewY) { double sine = sin(node.skewX); double cosine = cos(node.skewX); matrix.a = node.scaleX * cosine; matrix.b = node.scaleX * -sine; matrix.c = node.scaleY * sine; matrix.d = node.scaleY * cosine; } else { matrix.a = node.scaleX * cos(node.skewY); matrix.b = node.scaleX * sin(node.skewY); matrix.c = node.scaleY * sin(node.skewX); matrix.d = node.scaleY * cos(node.skewX); } matrix.tx = node.x; matrix.ty = node.y; } void TransformHelp::nodeToMatrix(const BaseData &node, Mat4 &matrix) { matrix = Mat4::IDENTITY; if (node.skewX == -node.skewY) { double sine = sin(node.skewX); double cosine = cos(node.skewX); matrix.m[0] = node.scaleX * cosine; matrix.m[1] = node.scaleX * -sine; matrix.m[4] = node.scaleY * sine; matrix.m[5] = node.scaleY * cosine; } else { matrix.m[0] = node.scaleX * cos(node.skewY); matrix.m[1] = node.scaleX * sin(node.skewY); matrix.m[4] = node.scaleY * sin(node.skewX); matrix.m[5] = node.scaleY * cos(node.skewX); } matrix.m[12] = node.x; matrix.m[13] = node.y; } void TransformHelp::matrixToNode(const AffineTransform &matrix, BaseData &node) { /* * In as3 language, there is a function called "deltaTransformPoint", it calculate a point used give Transform * but not used the tx, ty value. we simulate the function here */ helpPoint1.x = 0; helpPoint1.y = 1; helpPoint1 = PointApplyAffineTransform(helpPoint1, matrix); helpPoint1.x -= matrix.tx; helpPoint1.y -= matrix.ty; helpPoint2.x = 1; helpPoint2.y = 0; helpPoint2 = PointApplyAffineTransform(helpPoint2, matrix); helpPoint2.x -= matrix.tx; helpPoint2.y -= matrix.ty; node.skewX = -(atan2f(helpPoint1.y, helpPoint1.x) - 1.5707964f); node.skewY = atan2f(helpPoint2.y, helpPoint2.x); node.scaleX = sqrt(matrix.a * matrix.a + matrix.b * matrix.b); node.scaleY = sqrt(matrix.c * matrix.c + matrix.d * matrix.d); node.x = matrix.tx; node.y = matrix.ty; } void TransformHelp::matrixToNode(const Mat4 &matrix, BaseData &node) { /* * In as3 language, there is a function called "deltaTransformPoint", it calculate a point used give Transform * but not used the tx, ty value. we simulate the function here */ helpPoint1.x = 0; helpPoint1.y = 1; helpPoint1 = PointApplyTransform(helpPoint1, matrix); helpPoint1.x -= matrix.m[12]; helpPoint1.y -= matrix.m[13]; helpPoint2.x = 1; helpPoint2.y = 0; helpPoint2 = PointApplyTransform(helpPoint2, matrix); helpPoint2.x -= matrix.m[12]; helpPoint2.y -= matrix.m[13]; node.skewX = -(atan2f(helpPoint1.y, helpPoint1.x) - 1.5707964f); node.skewY = atan2f(helpPoint2.y, helpPoint2.x); node.scaleX = sqrt(matrix.m[0] * matrix.m[0] + matrix.m[1] * matrix.m[1]); node.scaleY = sqrt(matrix.m[4] * matrix.m[4] + matrix.m[5] * matrix.m[5]); node.x = matrix.m[12]; node.y = matrix.m[13]; } void TransformHelp::nodeConcat(BaseData &target, BaseData &source) { target.x += source.x; target.y += source.y; target.skewX += source.skewX; target.skewY += source.skewY; target.scaleX += source.scaleX; target.scaleY += source.scaleY; } void TransformHelp::nodeSub(BaseData &target, BaseData &source) { target.x -= source.x; target.y -= source.y; target.skewX -= source.skewX; target.skewY -= source.skewY; target.scaleX -= source.scaleX; target.scaleY -= source.scaleY; } }
DWORD WINAPI Classify_Data2(LPVOID lpParamter) { BaseDataInherit basedatainherit; basedatainherit.TIME_INTERVAL =DATA_TIME_INTERVAL; //默认时间间隔 BaseData *base; //基类指针 base= &basedatainherit; bool flag = false; //每次只处理一个数据 while(1) { //休盘时间清空数据 if(method_Rest_Time()) { Sleep(1000); //在休盘时间重置 清除内存中数据 //要改的地方 if (basedatainherit.tsmd_a->size()!=0) { basedatainherit.TIME_INTERVAL = DATA_TIME_INTERVAL; basedatainherit.contract=""; basedatainherit.compare_time=0; memset(&(basedatainherit.current_data),0,sizeof(basedatainherit.current_data)); memset(&(basedatainherit.compare_data),0,sizeof(basedatainherit.compare_data)); basedatainherit.tsmd_a = NULL; basedatainherit.tsmd_a= new map<string,BaseDataInherit*>(); base = NULL; base = &basedatainherit; } } //进入临界区 EnterCriticalSection(&cs); CThostFtdcDepthMarketDataField_Custom dd =cmdSpi_custom->methodGetDatas_After(); //释放临界区 LeaveCriticalSection(&cs); if (dd.TradingDay!=0) { flag = true; }else{ //睡眠10ms,防止cpu过高 20151222 加 Sleep(10); } if (flag) { ////////////////////////////////////////////////////////////////////////// //处理郑商所夜盘日期问题 if (dd.UpdateTime>=210000&&dd.UpdateTime<210300) { if ((string)(dd.ExchangeID)=="shfe") { TradingDay = dd.TradingDay; } } if (dd.UpdateTime>=210000||dd.UpdateTime<23000) { if ((string)(dd.ExchangeID)=="czce") { dd.TradingDay=TradingDay; } } ////////////////////////////////////////////////////////////////////////// flag = false; //转换数据 CThostFtdcDepthMarketDataField_Custom_Tick ct = methodChangeData(dd); if (!base->isExist((string)(ct.InstrumentID))) { base->addContractToMap(&ct); } else { base->updateData(&ct); } }//end flag }//end while }//end Classify_Data2
BaseData<Dtype>::BaseData(const BaseData<Dtype>& data) { length_ = data.length(); memcpy(cpu_data_, data.cpu_data(), sizeof(Dtype)*data.length()); }