Beispiel #1
0
void CMnemosynthDb::GenerateDelta (TArray<SMnemosynthUpdate> *retUpdates, CDatum *retdLocalUpdates)

//	GenerateDelta
//
//	Generates a list of changes since the last time we called this

	{
	CSmartLock Lock(m_cs);

	int i, j;

	//	Edge conditions

	if (m_Endpoints.GetCount() == 0)
		{
		*retdLocalUpdates = CDatum();
		return;
		}

	//	If we are not the central module, then we only need to
	//	generate a list of updates made by our own endpoint
	//	(and send it to our central module).

	if (!m_pProcess->IsCentralModule())
		{
		if (GetLocalEndpoint().dwSeqRecv > GetLocalEndpoint().dwSeqSent)
			{
			SMnemosynthUpdate *pUpdate = retUpdates->Insert();
			pUpdate->sDestEndpoint = strPattern("%s/CentralModule", m_pProcess->GetMachineName());

			//	Generate a payload for our updates

			CComplexArray *pEntries = new CComplexArray;
			for (i = 0; i < m_Collections.GetCount(); i++)
				{
				const CString &sCollection = m_Collections.GetKey(i);
				SCollection *pCollection = &m_Collections[i];

				for (j = 0; j < pCollection->Entries.GetCount(); j++)
					{
					SEntry *pEntry = &pCollection->Entries[j];
					if (pEntry->dwOwnerID == 0 && pEntry->dwSequence > GetLocalEndpoint().dwSeqSent)
						{
						CDatum dEntry = GenerateEntry(i, pCollection->Entries.GetKey(j), pEntry);
						pEntries->Insert(dEntry);

						//	If this entry is Nil then we can deleted. (We don't
						//	need it as a deletion stub since we just composed
						//	the update. If this message gets lost we need to
						//	resend everything).

						if (pCollection->Entries.GetValue(j).dValue.IsNil())
							{
							pCollection->Entries.Delete(j);
							j--;
							}
						}
					}
				}

			//	Create the payload

			CComplexStruct *pPayload = new CComplexStruct;
			pPayload->SetElement(STR_COLLECTIONS, GenerateCollectionsArray());
			pPayload->SetElement(STR_ENDPOINT, GetLocalEndpoint().sName);
			pPayload->SetElement(STR_ENTRIES, CDatum(pEntries));
			pPayload->SetElement(FIELD_PROCESS_ID, CDatum(GetLocalEndpoint().dwProcessID));

			//	Add it

			CDatum dLocalUpdates = CDatum(pPayload);
			pUpdate->Payloads.Insert(dLocalUpdates);

			//	Return it

			*retdLocalUpdates = dLocalUpdates;
			}
		else
			*retdLocalUpdates = CDatum();
		}

	//	Otherwise, loop over all endpoints and generate a different
	//	update entry for each one that we need to handle

	else
		{
		bool bFullUpdateNeeded = false;
		for (i = 1; i < m_Endpoints.GetCount(); i++)
			if (m_Endpoints[i].bFullUpdate)
				{
				bFullUpdateNeeded = true;
				break;
				}

		//	Collections

		CDatum dCollections = GenerateCollectionsArray();

		//	We end up creating one or two arrays of deltas. The first
		//	array has all the changes since we last generated a delta
		//	(this is used for endpoints that we updated last time).
		//
		//	The second array has a full set of data (this is for new
		//	endpoints).

		TArray<CComplexArray *> UpdateEntries;
		TArray<CComplexArray *> FullEntries;
		TArray<CDatum> UpdatePayloads;
		TArray<CDatum> FullPayloads;

		UpdateEntries.InsertEmpty(m_Endpoints.GetCount());
		UpdatePayloads.InsertEmpty(m_Endpoints.GetCount());
		if (bFullUpdateNeeded)
			{
			FullEntries.InsertEmpty(m_Endpoints.GetCount());
			FullPayloads.InsertEmpty(m_Endpoints.GetCount());
			}

		for (i = 0; i < m_Endpoints.GetCount(); i++)
			{
			UpdateEntries[i] = new CComplexArray;

			CComplexStruct *pStruct = new CComplexStruct;
			pStruct->SetElement(STR_COLLECTIONS, dCollections);
			pStruct->SetElement(STR_ENDPOINT, m_Endpoints[i].sName);
			pStruct->SetElement(STR_ENTRIES, CDatum(UpdateEntries[i]));
			pStruct->SetElement(FIELD_PROCESS_ID, CDatum(m_Endpoints[i].dwProcessID));
			UpdatePayloads[i] = CDatum(pStruct);

			if (bFullUpdateNeeded)
				{
				FullEntries[i] = new CComplexArray;

				pStruct = new CComplexStruct;
				pStruct->SetElement(STR_COLLECTIONS, dCollections);
				pStruct->SetElement(STR_ENDPOINT, m_Endpoints[i].sName);
				pStruct->SetElement(STR_ENTRIES, CDatum(FullEntries[i]));
				pStruct->SetElement(FIELD_PROCESS_ID, CDatum(m_Endpoints[i].dwProcessID));
				FullPayloads[i] = CDatum(pStruct);
				}
			}

		//	Loop over all entries in the database and add them to the
		//	appropriate payload arrays

		for (i = 0; i < m_Collections.GetCount(); i++)
			{
			const CString &sCollection = m_Collections.GetKey(i);
			SCollection *pCollection = &m_Collections[i];

			for (j = 0; j < pCollection->Entries.GetCount(); j++)
				{
				SEntry *pEntry = &pCollection->Entries[j];

				//	Get the endpoint for the owner of this collection

				int iOwner = FindEndpointIndex(pEntry->dwOwnerID);
				if (iOwner == -1)
					continue;

				//	Add to the update array

				if (pEntry->dwSequence > m_Endpoints[iOwner].dwSeqSent)
					{
					CDatum dEntry = GenerateEntry(i, pCollection->Entries.GetKey(j), pEntry);
					UpdateEntries[iOwner]->Insert(dEntry);

#ifdef DEBUG_MNEMOSYNTH
					printf("[CMnemosynthDb::GenerateDelta]: Endpoint %s %x\n", (LPSTR)m_Endpoints[iOwner].sName, m_Endpoints[iOwner].dwSeqSent);
#endif
					}

				//	Add to full array, if necessary

				if (bFullUpdateNeeded)
					{
					//	Don't bother inserting Nil entries (since this is a full
					//	update).

					if (!pEntry->dValue.IsNil())
						{
						CDatum dEntry = GenerateEntry(i, pCollection->Entries.GetKey(j), pEntry);
						FullEntries[iOwner]->Insert(dEntry);
						}
					}

				//	If this entry is Nil then we can deleted. (We don't
				//	need it as a deletion stub since we just composed
				//	the update. If this message gets lost we need to
				//	resend everything).

				if (pEntry->dValue.IsNil())
					{
					pCollection->Entries.Delete(j);
					j--;
					}
				}
			}

		//	Now iterate over all destination endpoints

		for (i = 1; i < m_Endpoints.GetCount(); i++)
			{
			SEndpoint *pDestEndpoint = &m_Endpoints[i];

#ifdef DEBUG_MNEMOSYNTH
			printf("[CMnemosynthDb::GenerateDelta]: Composing for endpoint %s %s%s.\n", (LPSTR)pDestEndpoint->sName, (pDestEndpoint->bCentralModule ? "CentralModule " : ""), (pDestEndpoint->bLocalMachine ? "local" : ""));
#endif

			//	If this is a local module, then send it any updates
			//	for everything except itself

			if (pDestEndpoint->bLocalMachine && !pDestEndpoint->bCentralModule)
				{
				SMnemosynthUpdate *pUpdate = NULL;

				for (j = 0; j < m_Endpoints.GetCount(); j++)
					if (i != j)
						{
						//	If we have no update entries, then skip.

						if (!pDestEndpoint->bFullUpdate
								&& UpdatePayloads[j].GetElement(STR_ENTRIES).GetCount() == 0)
							continue;

						//	Add an update entry

						if (pUpdate == NULL)
							{
							pUpdate = retUpdates->Insert();
							pUpdate->sDestEndpoint = pDestEndpoint->sName;
							}

						if (pDestEndpoint->bFullUpdate)
							pUpdate->Payloads.Insert(FullPayloads[j]);
						else
							pUpdate->Payloads.Insert(UpdatePayloads[j]);
						}
				}

			//	Otherwise, if this is a foreign central module, then
			//	send it any updates for all local endpoints

			else if (pDestEndpoint->bCentralModule && !pDestEndpoint->bLocalMachine)
				{
				SMnemosynthUpdate *pUpdate = NULL;

#ifdef DEBUG_MNEMOSYNTH
				if (pDestEndpoint->bFullUpdate)
					printf("[CMnemosynthDb::GenerateDelta]: Composing FULL update for %s\n", (LPSTR)pDestEndpoint->sName);
				else
					printf("[CMnemosynthDb::GenerateDelta]: Composing DIFF update for %s\n", (LPSTR)pDestEndpoint->sName);
#endif

				for (j = 0; j < m_Endpoints.GetCount(); j++)
					if (m_Endpoints[j].bLocalMachine)
						{
						//	If we have no update entries, then skip.

						if (!pDestEndpoint->bFullUpdate
								&& UpdatePayloads[j].GetElement(STR_ENTRIES).GetCount() == 0)
							continue;

#ifdef DEBUG_MNEMOSYNTH
						printf("[CMnemosynthDb::GenerateDelta]: Updates from %s\n", (LPSTR)m_Endpoints[j].sName);
#endif

						//	Add an update entry

						if (pUpdate == NULL)
							{
							pUpdate = retUpdates->Insert();
							pUpdate->sDestEndpoint = pDestEndpoint->sName;
							}

						if (pDestEndpoint->bFullUpdate)
							pUpdate->Payloads.Insert(FullPayloads[j]);
						else
							pUpdate->Payloads.Insert(UpdatePayloads[j]);
						}
				}
			}

		//	Local updates

		*retdLocalUpdates = UpdatePayloads[0];
		}

	//	Reset

	for (i = 0; i < m_Endpoints.GetCount(); i++)
		{
		m_Endpoints[i].dwSeqSent = m_Endpoints[i].dwSeqRecv;
		m_Endpoints[i].bFullUpdate = false;
		}

	m_ModifiedEvent.Reset();
	}
Beispiel #2
0
vector<Interaction> GetInteractions (Proposal *proposal1, Proposal *proposal2)
// list all possible pixel interations (occluder / occluded) between pixels of proposals 1 and 2
{
	// allocate
	AllocBuffer(proposal1);

	// all occluder/occluded - interaction that can occor for all combinations of proposals 1 and 2 
	vector<Interaction> interactions;

	// fill the buffer representing the right view
	for (int y = 0; y < _imgH; y++)
		for (int x = 0; x < _imgW; x++)
		{
			SurfaceModel *sm1 = proposal1->surfacemodels[y * _imgW + x];
			SurfaceModel *sm2 = proposal2->surfacemodels[y * _imgW + x];

			Entry entry0 = GenerateEntry (sm1, cvPoint (x,y));
			entry0.x_i = 0;
			AddEntry (entry0);

			Entry entry1 = GenerateEntry (sm2, cvPoint (x,y));
			entry1.x_i = 1;
			AddEntry (entry1);
		}

	// read the interactions
	// if a cell of the buffer contains more than 1 entry then the one of higher disparity
	// occludes all others of lower disparities
	for (int y = 0; y < _imgH; y++)
		for (int x = 0; x < _imgW; x++)
		{
			vector<Entry> *cell = Buffer[y * _imgW + x];

			if (cell->size() < 2)
				continue;

			for (int i = 0; i < cell->size() - 1; i++)
			{
				Entry occluder = cell->at(i);

				for (int j = i + 1; j < cell->size(); j++)
				{
					Entry occlusion = cell->at(j);

					// no interaction for identical surfaces
					// see paper (improved asymmetric occlusion model)
					if (occluder.proposalid == occlusion.proposalid &&
						occluder.segid == occlusion.segid)
						continue;

					// build occluder / occlusion pair with corresponding states
					Interaction interaction;

					interaction.first.left_p = occluder.left_p;
					interaction.first.x_i = occluder.x_i;

					interaction.second.left_p = occlusion.left_p;
					interaction.second.x_i = occlusion.x_i;
					
					interactions.push_back (interaction);
				}
			}
		}


	return interactions;
}
Beispiel #3
0
ForceInline void main2(int argc, TCHAR **argv)
{
    if (argc < 2)
    {
        _tprintf(_T("%s input_dir\n"), findname(argv[0]));
        return;
    }

    TCHAR  szOutFile[MAX_PATH];
    HANDLE hOut, hHeap;
    DWORD  dwLength, dwEntryCount;
    PAZTYPE PazType;
    TMyPAZEntry *pEntry;

    hHeap = GetProcessHeap();
    ghHeap = hHeap;
    for (int i = 1; i != argc; ++i)
    {
        Char  (*pPazHeader)[sizeof(headers[0])];
        DWORD dwAttributes;

        dwAttributes = GetFileAttributes(argv[i]);
        if (dwAttributes == -1)
        {
            _tprintf(_T("\"%s\" doesn't exist.\n"), argv[i]);
            continue;
        }
        else if ((dwAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
        {
            _tprintf(_T("%s isn't a directory.\n"), argv[i]);
            continue;
        }

        LPCSTR lpPath;

        lstrcpy(szOutFile, argv[i]);
        dwLength = lstrlen(szOutFile);
        if (szOutFile[dwLength - 1] == '\\')
            szOutFile[dwLength - 1] = 0;
        lstrcat(szOutFile, ".paz");

        lpPath = argv[i];
        PazType = NONE;
        if (i + 2 < argc)
        {
            int j = i + 1;
            if (argv[j][0] == '-' && ((argv[j][1] & 0xDF) == 'T'))
            {
                ++j;
                for (int k = 0; k != countof(szType); ++k)
                {
                    if (!lstrcmpi(szType[k], argv[j]))
                    {
                        i = j;
                        PazType = (PAZTYPE)k;
                        break;
                    }
                }
            }
        }
        else
        {
            PazType = GetPazTypeFromFileName(szOutFile);
        }

        if (PazType == NONE)
        {
            _tprintf(_T("Please specify one PAZ type by -t type or use a special file name.\n")
                _T("Following type is valid: \n\t")
                );
            for (int i = 0; i != countof(szType); ++i)
            {
                printf("%s ", szType[i]);
                if (i == countof(szType) / 2)
                    printf("\n\t");
            }

            break;
        }

        dwKeyIndex = GetKeyIndex(szType[PazType], &GameInfo[dwInfoIndex]);
        if (dwKeyIndex == -1)
        {
            printf("%s: don't know encryption key.\n", szOutFile);
            continue;
        }

        hOut = CreateFile(szOutFile,
                        GENERIC_READ|GENERIC_WRITE,
                        FILE_SHARE_READ|FILE_SHARE_WRITE,
                        NULL,
                        CREATE_ALWAYS,
                        FILE_ATTRIBUTE_NORMAL,
                        NULL);
        if (hOut == INVALID_HANDLE_VALUE)
        {
            _tprintf(_T("Can't create \"%s\"\n"), szOutFile);
            continue;
        }

        g_bIsMovie = IsMovie(szOutFile);
        bIsVoice = IsAudio(szOutFile);
        SetCurrentDirectory(lpPath);
        dwEntryCount = GenerateEntry(&pEntry);
        if (dwEntryCount == 0 || pEntry == NULL)
        {
            _tprintf(_T("There is no file in \"%s\"\n"), argv[i]);
            continue;
        }

        bNeedXor = strnicmp(szType[PazType], "pm", 2) != 0;
        _tprintf(_T("Packing %s ...\n"), szOutFile);
        if (bNeedXor)
        {
            pPazHeader = (Char (*)[32])headers[dwInfoIndex];
        }
        else
            pPazHeader = (Char (*)[32])headers[countof(headers) - 1];

        WriteFile(hOut, pPazHeader, sizeof(*pPazHeader), &dwLength, NULL);
        WriteEntry(hOut, pEntry, dwEntryCount, False);

        WriteFileToPaz(hOut, pEntry, dwEntryCount, PazType);
        WriteEntry(hOut, pEntry, dwEntryCount, True);

//        HeapFree(hHeap, 0, pEntry);
        FreeFileList(pEntry);
        CloseHandle(hOut);
    }
}