void configExit() { releaseCache(); releaseVolume(); }
Transform12 registerVolume(Volume* baseVol1, Volume* regVol1) { Volume* baseVol2 = halfSample(baseVol1); Volume* baseVol4 = halfSample(baseVol2); Volume* baseVol8 = halfSample(baseVol4); Volume* regVol2 = halfSample(regVol1); Volume* regVol4 = halfSample(regVol2); Volume* regVol8 = halfSample(regVol4); int t1=clock(); Transform12 result; float medianScale=0; //8mm stage start initVolumeData(baseVol8,regVol8); float4* coarseGrid=new float4[coarseAngleCount*coarseAngleCount*coarseAngleCount]; coarseRegister(baseVol8,regVol8,coarseGrid,medianScale); float4* finerGrid=new float4[finerAngleCount*finerAngleCount*finerAngleCount]; float* finerResults=new float[finerAngleCount*finerAngleCount*finerAngleCount]; buildFinerGrid(coarseGrid,finerGrid); finerRegister( baseVol8, regVol8, finerGrid, finerResults, medianScale); freeVolumeData(); int* minima=new int[finerAngleCount*finerAngleCount*finerAngleCount / 8]; int minimaCount=0; findMinima(finerResults,minima,minimaCount); Transform7 globalMinima[FLIRT_MINIMA_COUNT]; sortMinima(finerGrid,finerResults,minima,minimaCount,globalMinima); printf("MedianScale is:%f,minimaCount is%d\n",medianScale,minimaCount); //4mm stage start initVolumeData(baseVol4,regVol4); Transform7 higherResStart[FLIRT_HIGHER_RESOLUTION_START]; Transform12 t12[FLIRT_HIGHER_RESOLUTION_START]; float finalResult[FLIRT_HIGHER_RESOLUTION_START]; perturbationStage(baseVol4,regVol4,globalMinima,higherResStart); freeVolumeData(); //2mm stage start initVolumeData(baseVol2,regVol2); for(int i=0;i<FLIRT_HIGHER_RESOLUTION_START;i++) t12[i]=optimize2mm(baseVol2,regVol2,higherResStart[i]); freeVolumeData(); //1mm stage start initVolumeData(baseVol1,regVol1); int t2=clock(); printf("\n\ntime used:%dms,global count is:%d\n",t2-t1,globalCount); float minValue=0; for(int i=0;i<FLIRT_HIGHER_RESOLUTION_START;i++) { Transform12 T=t12[i]; finalResult[i]=optimize1mm(baseVol1,regVol1,T); t12[i]=T; if(minValue>finalResult[i])result=t12[i]; printf("12 DOF 1mm:rotation(%f,%f,%f),trans(%f,%f,%f),scale(%f,%f,%f),skew(%f,%f,%f),value is:%f\n",T.rotation.x,T.rotation.y,T.rotation.z,T.translation.x,T.translation.y,T.translation.z,T.scale.x,T.scale.y,T.scale.z,T.skew.x,T.skew.y,T.skew.z,finalResult[i]); } freeVolumeData(); t2=clock(); printf("\n\ntime used:%dms,global count is:%d\n",t2-t1,globalCount); releaseVolume(baseVol2); releaseVolume(baseVol4); releaseVolume(baseVol8); releaseVolume(regVol2); releaseVolume(regVol4); releaseVolume(regVol8); return result; }
HRESULT WalkTreeFromPart( IPart *pPart, EDataFlow eDirection, bool bFollowConnector, int iTabLevel /* = 0 */ ) { HRESULT hr = S_OK; UINT nId = 0; hr = pPart->GetLocalId(&nId); if (FAILED(hr)) { LOG(L"Could not get part id: hr = 0x%08x", hr); return hr; } LPWSTR pwszPartName = NULL; hr = pPart->GetName(&pwszPartName); if (FAILED(hr)) { LOG(L"Could not get part name: hr = 0x%08x", hr); return hr; } CoTaskMemFreeOnExit freeName(pwszPartName); Tab(iTabLevel); LOG(L"0x%x: %s", nId, pwszPartName); // see if this is a volume node part IAudioVolumeLevel *pVolume = NULL; hr = pPart->Activate(CLSCTX_ALL, __uuidof(IAudioVolumeLevel), (void**)&pVolume); if (E_NOINTERFACE == hr) { // not a volume node } else if (FAILED(hr)) { LOG(L"Unexpected failure trying to activate IAudioVolumeLevel: hr = 0x%08x", hr); return hr; } else { // it's a volume node... ReleaseOnExit releaseVolume(pVolume); hr = DisplayVolume(pVolume, iTabLevel); if (FAILED(hr)) { LOG(L"DisplayVolume failed: hr = 0x%08x", hr); return hr; } } // see if this is a mute node part IAudioMute *pMute = NULL; hr = pPart->Activate(CLSCTX_ALL, __uuidof(IAudioMute), (void**)&pMute); if (E_NOINTERFACE == hr) { // not a mute node } else if (FAILED(hr)) { LOG(L"Unexpected failure trying to activate IAudioMute: hr = 0x%08x", hr); return hr; } else { // it's a mute node... ReleaseOnExit releaseMute(pMute); hr = DisplayMute(pMute, iTabLevel); if (FAILED(hr)) { LOG(L"DisplayMute failed: hr = 0x%08x", hr); return hr; } } // see if this is a jack description part IKsJackDescription *pKsJackDescription = NULL; hr = pPart->Activate(CLSCTX_ALL, __uuidof(IKsJackDescription), (void**)&pKsJackDescription); if (E_NOINTERFACE == hr) { // not a jack description part } else if (FAILED(hr)) { LOG(L"Unexpected failure trying to activate IKsJackDescription: hr = 0x%08x", hr); return hr; } else { // it's a mute node... ReleaseOnExit releaseJackDescription(pKsJackDescription); hr = DisplayKsJackDescription(pKsJackDescription, iTabLevel); if (FAILED(hr)) { LOG(L"DisplayKsJackDescription failed: hr = 0x%08x", hr); return hr; } } // get the list of incoming or outgoing parts, according to the direction IPartsList *pParts = NULL; hr = ( eRender == eDirection ? pPart->EnumPartsIncoming(&pParts) : pPart->EnumPartsOutgoing(&pParts) ); if (E_NOTFOUND == hr) { // not an error... we've just reached the end of the path } else if (FAILED(hr)) { LOG(L"Couldn't enum next parts: hr = 0x%08x", hr); return hr; } else { ReleaseOnExit releaseOnExit(pParts); UINT nParts = 0; hr = pParts->GetCount(&nParts); if (FAILED(hr)) { LOG(L"Couldn't get count of incoming parts: hr = 0x%08x", hr); return hr; } // walk the tree on each incoming/outgoing part recursively for (UINT n = 0; n < nParts; n++) { IPart *pNextPart = NULL; hr = pParts->GetPart(n, &pNextPart); if (FAILED(hr)) { LOG(L"Couldn't get part #%u (0-based) of %u (1-based:) hr = 0x%08x", n, nParts, hr); return hr; } ReleaseOnExit releaseNextPart(pNextPart); // if the incoming/outgoing part is a connector, follow it hr = WalkTreeFromPart(pNextPart, eDirection, true, iTabLevel + 1); if (FAILED(hr)) { LOG(L"Couldn't walk tree on part #%u (0-based) of %u (1-based:) hr = 0x%08x", n, nParts, hr); return hr; } } } if (bFollowConnector) { // if this part is a connector, do the connector dance IConnector *pConnHere = NULL; hr = pPart->QueryInterface(IID_PPV_ARGS(&pConnHere)); if (E_NOINTERFACE == hr) { // that's fine } else if (FAILED(hr)) { LOG(L"Unexpected failure getting the connector on the endpoint: hr = 0x%08x", hr); return hr; } else { ReleaseOnExit releaseConnHere(pConnHere); // get the connector on the other side IConnector *pConnOtherSide = NULL; hr = pConnHere->GetConnectedTo(&pConnOtherSide); if (E_NOTFOUND == hr) { // that's fine, it just isn't connected to anything } else if (FAILED(hr)) { LOG(L"Couldn't get the connector on the upstream device: hr = 0x%08x", hr); return __LINE__; } else { ReleaseOnExit releaseConnOtherSide(pConnOtherSide); // QI on the device's connector for IPart IPart *pPartOtherSide = NULL; hr = pConnOtherSide->QueryInterface(IID_PPV_ARGS(&pPartOtherSide)); if (FAILED(hr)) { LOG(L"Couldn't get the part on the other side: hr = 0x%08x", hr); return __LINE__; } ReleaseOnExit releasePartOtherSide(pPartOtherSide); // get the device topology interface for the other side IDeviceTopology *pDTOtherSide = NULL; hr = pPartOtherSide->GetTopologyObject(&pDTOtherSide); if (FAILED(hr)) { LOG(L"Couldn't get the other side's device topology: hr = 0x%08x", hr); return __LINE__; } ReleaseOnExit releaseDTOtherSide(pDTOtherSide); // get the device name for the other side LPWSTR pwszDeviceName = NULL; hr = pDTOtherSide->GetDeviceId(&pwszDeviceName); if (FAILED(hr)) { LOG(L"Could not get device name: hr = 0x%08x", hr); return hr; } CoTaskMemFreeOnExit freeDeviceName(pwszDeviceName); Tab(iTabLevel); LOG(L"%s", pwszDeviceName); // walk the other side's tree // but don't follow the connector back to here hr = WalkTreeFromPart(pPartOtherSide, eDirection, false, iTabLevel + 1); if (FAILED(hr)) { LOG(L"Couldn't walk the tree: hr = 0x%08x", hr); return __LINE__; } } } } return S_OK; }