示例#1
0
static inline QITableEntry *
GetOffsetsFromSlimWrapper(JSObject *obj)
{
    NS_ASSERTION(IS_SLIM_WRAPPER(obj), "What kind of object is this?");
    return GetOffsets(static_cast<nsISupports*>(xpc_GetJSPrivate(obj)),
                      GetSlimWrapperProto(obj));
}
void CSmoothingAlgorithm::BilateralSmooth(KW_Mesh& Mesh,vector<Vertex_handle>& vecVertexToSmooth,double dSigmaC,double dKernelSize,double dSigmaS,int iNormalRingNum)
{
	//calculate the normal,just one-ring involved at present
	OBJHandle::UnitizeCGALPolyhedron(Mesh,false,false);
	
	if (dSigmaC==0)
	{
		dSigmaC=0.05;
		dKernelSize=dSigmaC*2;
	}

	assert(dKernelSize==2*dSigmaC);

	vector<Point_3> vecNewPos;

	for (unsigned int iVertex=0;iVertex<vecVertexToSmooth.size();iVertex++)
	{
		//get kernel vertices and their distances to the current vertex
		vector<Vertex_handle> vecKernelVertex;
		vector<double> vecDistance;
		GetKernelVertex(Mesh,vecVertexToSmooth.at(iVertex),dKernelSize,vecKernelVertex,vecDistance);

		//get offsets and derivation
		vector<double> vecOffset;
		GetOffsets(vecVertexToSmooth.at(iVertex),vecKernelVertex,vecOffset);
		double dDerivation=GeometryAlgorithm::GetDerivation(vecOffset);
		dSigmaS=dDerivation;
		//compute new positions
		double dSum,dNormalizer;
		dSum=dNormalizer=0;
		for (unsigned int iKernelVertex=0;iKernelVertex<vecKernelVertex.size();iKernelVertex++)
		{
			double dWC=exp(-vecDistance.at(iKernelVertex)*vecDistance.at(iKernelVertex)/(2*dSigmaC*dSigmaC));
			double dWS=exp(-vecOffset.at(iKernelVertex)*vecOffset.at(iKernelVertex)/(2*dSigmaS*dSigmaS));
			dSum=dSum+dWC*dWS*vecOffset.at(iKernelVertex);
			dNormalizer=dNormalizer+dWC*dWS;
		}
		Vector_3 VectorToMove=vecVertexToSmooth.at(iVertex)->normal()*(dSum/dNormalizer);
		if (dSum==0)
		{
			VectorToMove=Vector_3(0,0,0);
		}
		//DBWindowWrite("vertex: %d  VectorToMove: %f %f %f\n",iVertex,VectorToMove.x(),VectorToMove.y(),VectorToMove.z());
		Point_3 NewPos=vecVertexToSmooth.at(iVertex)->point()+VectorToMove;
		vecNewPos.push_back(NewPos);
	}

	//update vertex position
	for (unsigned int i=0;i<vecNewPos.size();i++)
	{
		//DBWindowWrite("old pos: %f %f %f\n",vecVertexToSmooth.at(i)->point().x(),vecVertexToSmooth.at(i)->point().y(),vecVertexToSmooth.at(i)->point().z());
		//DBWindowWrite("new pos: %f %f %f\n",vecNewPos.at(i).x(),vecNewPos.at(i).y(),vecNewPos.at(i).z());
		vecVertexToSmooth.at(i)->point()=vecNewPos.at(i);
	}

	OBJHandle::UnitizeCGALPolyhedron(Mesh,false,false);
	Mesh.SetRenderInfo(true,true,false,false,false);
}
示例#3
0
float CollisionVolume::GetPointSurfaceDistance(const CFeature* f, const LocalModelPiece* /*lmp*/, const float3& p) const {
	CMatrix44f mat = f->GetTransformMatrixRef();

	mat.Translate(f->relMidPos * WORLD_TO_OBJECT_SPACE);
	mat.Translate(GetOffsets());
	mat.InvertAffineInPlace();

	return (GetPointSurfaceDistance(mat, p));
}
示例#4
0
  bool AreaWayIndex::GetOffsets(double minlon,
                                double minlat,
                                double maxlon,
                                double maxlat,
                                const std::vector<TypeSet>& wayTypes,
                                size_t maxWayCount,
                                std::vector<FileOffset>& offsets) const
  {
    if (!scanner.IsOpen()) {
      if (!scanner.Open(datafilename,FileScanner::LowMemRandom,true)) {
        log.Error() << "Error while opening " << scanner.GetFilename() << " for reading!";
        return false;
      }
    }

    bool                           sizeExceeded=false;
    std::unordered_set<FileOffset> newOffsets;

    offsets.reserve(std::min(100000u,(uint32_t)maxWayCount));
    newOffsets.reserve(std::min(100000u,(uint32_t)maxWayCount));

    for (size_t i=0; i<wayTypes.size(); i++) {
      newOffsets.clear();

      for (TypeId type=0;
          type<wayTypeData.size();
          ++type) {
        if (wayTypes[i].IsTypeSet(type)) {
          if (!GetOffsets(wayTypeData[type],
                          minlon,
                          minlat,
                          maxlon,
                          maxlat,
                          maxWayCount,
                          newOffsets,
                          offsets.size(),
                          sizeExceeded)) {
            return false;
          }

          if (sizeExceeded) {
            return true;
          }
        }
      }

      // Copy data from temporary set to final vector

      offsets.insert(offsets.end(),newOffsets.begin(),newOffsets.end());
    }

    //std::cout << "Found " << wayWayOffsets.size() << "+" << relationWayOffsets.size()<< " offsets in 'areaway.idx'" << std::endl;

    return true;
  }
示例#5
0
JSBool
xpc_qsUnwrapThisFromCcxImpl(XPCCallContext &ccx,
                            const nsIID &iid,
                            void **ppThis,
                            nsISupports **pThisRef,
                            jsval *vp)
{
    nsISupports *native = ccx.GetIdentityObject();
    if(!native)
        return xpc_qsThrow(ccx.GetJSContext(), NS_ERROR_XPC_HAS_BEEN_SHUTDOWN);

    nsresult rv = getNative(native, GetOffsets(native, ccx.GetProto()),
                            ccx.GetFlattenedJSObject(), iid, ppThis, pThisRef,
                            vp);
    if(NS_FAILED(rv))
        return xpc_qsThrow(ccx.GetJSContext(), rv);
    return JS_TRUE;
}
示例#6
0
float CollisionVolume::GetPointSurfaceDistance(const CUnit* u, const LocalModelPiece* lmp, const float3& p) const {
	const CollisionVolume* vol = u->collisionVolume;

	CMatrix44f mat = u->GetTransformMatrix(true);
	float3 off = GetOffsets();

	// Unit::GetTransformMatrix does not include this
	// (its translation component is pos, not midPos)
	mat.Translate(u->relMidPos * WORLD_TO_OBJECT_SPACE);

	if (vol->DefaultToPieceTree() && lmp != NULL) {
		// NOTE: if we get here, then <this> is the piece-volume
		assert(this == lmp->GetCollisionVolume());

		// need to transform into piece-space
		mat = mat * lmp->GetModelSpaceMatrix();
		off = -off;
	}

	mat.Translate(off);
	mat.InvertAffineInPlace();

	return (GetPointSurfaceDistance(mat, p));
}
示例#7
0
IDL_VPTR rdObjmask(int argc, IDL_VPTR *argv, char *argk) {

    /* the desired atlas image. */
    ATLAS_IMAGE *ai;

    /* The fits file */
    FITS *fits;

    char *atlasFileName;  // The input file name

    IDL_VPTR idlistVptr; // optional idlist input keyword
    IDL_MEMINT* idlist;
    IDL_MEMINT nid=0;
    int idiscopy=0;

    IDL_MEMINT nrows=0;  // actual number of rows in file
    IDL_MEMINT i=0, j=0;
  
    IDL_VPTR result;  // The result and temporary copies
    char* resptr;
    char* rowptr;
    char* elptr;
    IDL_LONG elval;
    int elsize;

    // Structure definition
    void* sdef;

    // offsets structure
    offsetstruct os;



    // First make sure IDL_LONG is 4-byte int
    elsize=sizeof(IDL_LONG);
    if (elsize != 4)
    {
        IDL_Message(IDL_M_NAMED_GENERIC, IDL_MSG_LONGJMP, "sizeof(IDL_LONG) must be 4");
    }


    /* Get the keywords */
    (void) IDL_KWProcessByOffset(argc, argv, argk, kw_pars, 
            (IDL_VPTR *) 0, 1, &kw);

    /* Check arguments */
    if (nParams(argc) < 1)
    {
        IDL_Message(IDL_M_NAMED_GENERIC, IDL_MSG_INFO,
                "Syntax: struct = rdObjmask(atlasFile, idlist=, status=)");
        setStatus(FAILURE);
        return(IDL_GettmpInt(-1));   
    }




    /* get file name and open fits file */
    atlasFileName = getFileNameVal(argv[0]);

    if((fits = open_fits_table(atlasFileName, 1)) == NULL) {
        /* Memory is cleaned up in open_fits_table() */
        setStatus(FAILURE);
        return(IDL_GettmpInt(-1));   
    }
    nrows = fits->naxis2;




    // See if idlist was sent, else generate a list of all
    if (kw.idlist_there)
    {
        /* make sure it is a MEMINT. Copy if needed */
        idlistVptr = getAsMEMINT(argv[1], &idiscopy);
        IDL_VarGetData(idlistVptr, &nid, (char **) &idlist, IDL_TRUE);
    } 
    else
    {
        idiscopy=1;
        nid=nrows;
        idlist = (IDL_MEMINT *) calloc(nrows, sizeof(IDL_MEMINT));
        for (i=1;i<=nrows;i++)
            idlist[i-1] = i;
    }



    /* structure definition and create output */ 
    sdef = IDL_MakeStruct(0, stags);
    resptr = IDL_MakeTempStructVector(sdef, nid, &result, IDL_TRUE); 
    os = GetOffsets(sdef);




    /* Copy in the info */
    for (i=0;i<nid;i++)
    {
        // Point to the appropriate row in output data
        rowptr = (char *) result->value.s.arr->data + i*( result->value.arr->elt_len );

        // Copy id.  Do it here since if the object has no atlas image
        // it wouldn't be copied
        elval = (IDL_LONG) idlist[i];
        elptr = rowptr + os.id;
        memcpy(elptr, &elval, elsize);


        // Read the atlas image
        ai = read_atlas_image(fits, (int) idlist[i]);


        // In what follows, copy -1 if the ai is invalid
        if (ai != NULL)
        {
            // Copy run
            elval = (IDL_LONG) ai->run;
            elptr = rowptr + os.run;
            memcpy(elptr, &elval, elsize);
            // Copy rerun
            elval = (IDL_LONG) ai->rerun;
            elptr = rowptr + os.rerun;
            memcpy(elptr, &elval, elsize);
            // Copy camcol 
            elval = (IDL_LONG) ai->camCol;
            elptr = rowptr + os.camcol;
            memcpy(elptr, &elval, elsize);
            // Copy field
            elval = (IDL_LONG) ai->field;
            elptr = rowptr + os.field;
            memcpy(elptr, &elval, elsize);
            // Copy id
            //elval = (IDL_LONG) ai->id;
            //elptr = rowptr + os.id;
            //memcpy(elptr, &elval, elsize);
            // Copy parent 
            elval = (IDL_LONG) ai->parent;
            elptr = rowptr + os.parent;
            memcpy(elptr, &elval, elsize);


            // copy row0 
            elptr = rowptr + os.row0;
            for (j=0;j<5;j++)
            {
                if (ai->id > 0)
                    elval = (IDL_LONG) (ai->master_mask->rmin + ai->drow[j]);
                else
                    elval=-1;
                memcpy(elptr, &elval, elsize);
                elptr+=elsize;
            }
            // copy col0 
            elptr = rowptr + os.col0;
            for (j=0;j<5;j++)
            {
                if (ai->id > 0)
                    elval = (IDL_LONG) (ai->master_mask->cmin + ai->dcol[j]);
                else
                    elval=-1;
                memcpy(elptr, &elval, elsize);
                elptr+=elsize;
            }
            // copy rowmax
            elptr = rowptr + os.rowmax;
            for (j=0;j<5;j++)
            {
                if (ai->id > 0)
                    elval = (IDL_LONG) (ai->master_mask->rmax + ai->drow[j]);
                else
                    elval=-1;
                memcpy(elptr, &elval, elsize);
                elptr+=elsize;
            }
            // copy colmax 
            elptr = rowptr + os.colmax;
            for (j=0;j<5;j++)
            {
                if (ai->id > 0)
                    elval = (IDL_LONG) (ai->master_mask->cmax + ai->dcol[j]);
                else
                    elval=-1;
                memcpy(elptr, &elval, elsize);
                elptr+=elsize;
            }


            // copy drow
            elptr = rowptr + os.drow;
            for (j=0;j<5;j++)
            {
                if (ai->id > 0)
                    elval = (IDL_LONG) (ai->drow[j]);
                else
                    elval = -1;
                memcpy(elptr, &elval, elsize);
                elptr+=elsize;
            }
            // copy dcol 
            elptr = rowptr + os.dcol;
            for (j=0;j<5;j++)
            {
                if (ai->id > 0)
                    elval = (IDL_LONG) (ai->dcol[j]);
                else
                    elval = -1;
                memcpy(elptr, &elval, elsize);
                elptr+=elsize;
            }

            phAtlasImageDel(ai,1);
        }
    }

    /* clean up */
    phFitsDel(fits);  

    if (kw.idlist_there & idiscopy)
        IDL_Deltmp(idlistVptr);
    else
        free(idlist);

    /* Clean up the keyword info */
    IDL_KW_FREE;

    setStatus(SUCCESS);
    //return(IDL_GettmpInt(-1));   
    return(result);

}
示例#8
0
bool InjectDLL(DWORD processID, const char* dllLocation)
{
    // gets a module handler which loaded by the process which
    // should be injected
    HMODULE hModule = GetModuleHandle("kernel32.dll");
    if (!hModule)
    {
        printf("ERROR: Can't get 'kernel32.dll' handle, ");
        printf("ErrorCode: %u\n", GetLastError());
        return false;
    }

    // gets the address of an exported function which can load DLLs
    FARPROC loadLibraryAddress = GetProcAddress(hModule, "LoadLibraryA");
    if (!loadLibraryAddress)
    {
        printf("ERROR: Can't get function 'LoadLibraryA' address, ");
        printf("ErrorCode: %u\n", GetLastError());
        return false;
    }

    // opens the process which should be injected
    HANDLE hProcess = OpenClientProcess(processID);
    if (!hProcess)
    {
        printf("Process [%u] '%s' open is failed.\n", processID, lookingProcessName);
        return false;
    }
    printf("\nProcess [%u] '%s' is opened.\n", processID, lookingProcessName);

    // gets the build number
    WORD buildNumber = GetBuildNumberFromProcess(hProcess);
    // error occured
    if (!buildNumber)
    {
        printf("Can't determine build number.\n");
        CloseHandle(hProcess);
        return false;
    }
    printf("Detected build number: %hu\n", buildNumber);

    // checks this build is supported or not
    HookEntry hookEntry;
    if (!GetOffsets(NULL, buildNumber, &hookEntry))
    {
        printf("ERROR: This build number is not supported.\n");
        CloseHandle(hProcess);
        return false;
    }

    // allocates memory for the DLL location string
    LPVOID allocatedMemoryAddress = VirtualAllocEx(hProcess, NULL, strlen(dllLocation), MEM_COMMIT, PAGE_READWRITE);
    if (!allocatedMemoryAddress)
    {
        printf("ERROR: Virtual memory allocation is failed, ");
        printf("ErrorCode: %u.\n", GetLastError());
        CloseHandle(hProcess);
        return false;
    }

    // writes the DLL location string to the process
    // so this is the parameter which will be passed to LoadLibraryA
    if (!WriteProcessMemory(hProcess, allocatedMemoryAddress, dllLocation, strlen(dllLocation), NULL))
    {
        printf("ERROR: Process memory writing is failed, ");
        printf("ErrorCode: %u\n", GetLastError());
        VirtualFreeEx(hProcess, allocatedMemoryAddress, 0, MEM_RELEASE);
        CloseHandle(hProcess);
        return false;
    }

    // creates a thread that runs in the virtual address space of
    // the process which should be injected and gives the
    // parameter (allocatedMemoryAddress) to LoadLibraryA(loadLibraryAddress)
    HANDLE hRemoteThread = CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)loadLibraryAddress, allocatedMemoryAddress, 0, NULL);
    if (!hRemoteThread)
    {
        printf("ERROR: Remote thread creation is failed, ");
        printf("ErrorCode: %u\n", GetLastError());
        VirtualFreeEx(hProcess, allocatedMemoryAddress, 0, MEM_RELEASE);
        CloseHandle(hProcess);
        return false;
    }

    // waits until the DLL's main function returns
    WaitForSingleObject(hRemoteThread, INFINITE);

    // frees resources
    VirtualFreeEx(hProcess, allocatedMemoryAddress, 0, MEM_RELEASE);
    CloseHandle(hRemoteThread);
    CloseHandle(hProcess);

    return true;
}
示例#9
0
DWORD MainThreadControl(LPVOID /* param */)
{
    // creates the console
    if (!ConsoleManager::Create(&isSigIntOccured))
        FreeLibraryAndExitThread((HMODULE)instanceDLL, 0);

    // some info
    printf("Welcome to SzimatSzatyor, a WoW injector sniffer.\n");
    printf("SzimatSzatyor is distributed under the GNU GPLv3 license.\n");
    printf("Source code is available at: ");
    printf("http://github.com/Anubisss/SzimatSzatyor\n\n");

    printf("Press CTRL-C (CTRL then c) to stop sniffing ");
    printf("(and exit from the sniffer).\n");
    printf("Note: you can simply re-attach the sniffer without ");
    printf("restarting the WoW.\n\n");

    // gets the build number
    buildNumber = GetBuildNumberFromProcess();
    // error occured
    if (!buildNumber)
    {
        printf("Can't determine build number.\n\n");
        system("pause");
        FreeLibraryAndExitThread((HMODULE)instanceDLL, 0);
    }
    printf("Detected build number: %hu\n", buildNumber);

    // checks this build is supported or not
    if (!GetOffsets(instanceDLL, buildNumber, &hookEntry))
    {
        printf("ERROR: This build number is not supported.\n\n");
        system("pause");
        FreeLibraryAndExitThread((HMODULE)instanceDLL, 0);
    }

    // get the base address of the current process
    DWORD baseAddress = (DWORD)GetModuleHandle(NULL);

    DWORD localeAddress = hookEntry.locale;
    // locale stored in reversed string (enGB as BGne...)
    if (localeAddress)
    {
        for (int i = 3; i >= 0; --i)
            locale[i] = *(char*)(baseAddress + localeAddress++);
        printf("Detected client locale: %s\n", locale);
    }

    // gets where is the DLL which injected into the client
    DWORD dllPathSize = GetModuleFileName((HMODULE)instanceDLL, dllPath, MAX_PATH);
    if (!dllPathSize)
    {
        printf("\nERROR: Can't get the injected DLL's location, ");
        printf("ErrorCode: %u\n\n", GetLastError());
        system("pause");
        FreeLibraryAndExitThread((HMODULE)instanceDLL, 0);
    }
    printf("\nDLL path: %s\n", dllPath);

    // gets address of NetClient::Send2
    sendAddress = baseAddress + hookEntry.send_2;
    // hooks client's send function
    HookManager::Hook(sendAddress, (DWORD)SendHook, machineCodeHookSend, defaultMachineCodeSend);
    printf("Send is hooked.\n");

    // gets address of NetClient::ProcessMessage
    recvAddress = baseAddress + hookEntry.recive;
    // hooks client's recv function
    HookManager::Hook(recvAddress, (DWORD)RecvHook, machineCodeHookRecv, defaultMachineCodeRecv);
    printf("Recv is hooked.\n");

    // loops until SIGINT (CTRL-C) occurs
    while (!isSigIntOccured)
        Sleep(50); // sleeps 50 ms to be nice

    // unhooks functions
    HookManager::UnHook(sendAddress, defaultMachineCodeSend);
    HookManager::UnHook(recvAddress, defaultMachineCodeRecv);

    // shutdowns the sniffer
    // note: after that DLL's entry point will be called with
    // reason DLL_PROCESS_DETACH
    FreeLibraryAndExitThread((HMODULE)instanceDLL, 0);
    return 0;
}
示例#10
0
void SampleSwarm::Run(std::string pWorkDir, std::string pFileExt, int pZeros, int pStartFrame, int pRectNum, int pRectStep,
	int pLeft, int pTop, int pRectW, int pRectH)
{
	int curFrame = pStartFrame;
	std::string curFrameName = "";
	cv::namedWindow("output");
	cv::Mat imRgb, imGray;

	m_top = pTop;
	m_left = pLeft;
	m_rectNum = pRectNum;
	m_rectStepX = (float)pRectStep;
	m_rectStepY = (float)pRectStep;
	m_rectW = pRectW;
	m_rectH = pRectH;
	m_rects = new cv::Rect[pRectNum * pRectNum];
	m_centerX = (int)(m_left + (m_rectNum - 1) * m_rectStepX / 2 + m_rectW / 2);
	m_centerY = (int)(m_top + (m_rectNum - 1) * m_rectStepY / 2 + m_rectH / 2);
	m_scaleX = 1;
	m_scaleY = 1;
	m_scale = 1;

	// Set rects to their initial positions and get orig offsets
	ArrangeRects();

	// The Mosse Tracker learning rate. Read the paper for more information
	float learnRate = 0.08f;

	// For FPS counting
	double dt = 0;
	double dtAcc = 0;
	bool firstFps = true;
	double alpha = 0.05;
	LARGE_INTEGER accTimePrecStart;
	LARGE_INTEGER accTimePrecEnd;
	LARGE_INTEGER accTimePrecFreq;
	QueryPerformanceFrequency(&accTimePrecFreq);

	while (true)
	{
		// Generate new file name
		curFrameName = std::to_string(curFrame);
		curFrameName.insert(0, pZeros - curFrameName.length(), '0');
		curFrameName = std::string(pWorkDir).append(curFrameName).append(pFileExt);

		// Read file
		imRgb = cv::imread(curFrameName);
		if (imRgb.empty()) break;					// No more files
		cv::cvtColor(imRgb, imGray, CV_RGB2GRAY);	// Convert to graysacle

		// Call tracker
		if (curFrame == pStartFrame)
		{
			for (int i = 0; i < pRectNum * pRectNum; ++i)
				Mosse_Init(imGray.ptr(), (int)imGray.step, m_rects[i].x, m_rects[i].y, m_rects[i].width, m_rects[i].height, learnRate);
		}
		else
		{
			QueryPerformanceCounter(&accTimePrecStart);

			for (int i = 0; i < pRectNum * pRectNum; ++i)
				Mosse_OnFrame(i, imGray.ptr(), (int)imGray.step, m_rects[i].x, m_rects[i].y, m_rects[i].width, m_rects[i].height);

			// Estimate new position
			GetOffsets();
			m_left += m_dx;
			m_top += m_dy;
			m_centerX += m_dx;
			m_centerY += m_dy;

			// Estimate new scale
			GetScale();

			// Set rects to the new position
			ArrangeRects();

			// Learn new rects
			for (int i = 0; i < pRectNum * pRectNum; ++i)
				Mosse_Train(i, imGray.ptr(), (int)imGray.step, m_rects[i].x, m_rects[i].y, m_rects[i].width, m_rects[i].height);

			// Count FPS
			QueryPerformanceCounter(&accTimePrecEnd);
			dt = (double)(accTimePrecEnd.QuadPart - accTimePrecStart.QuadPart);
			dt /= accTimePrecFreq.QuadPart;

			if (firstFps)
			{
				firstFps = false;
				dtAcc = dt;
			}
			else
				dtAcc = dt * alpha + dtAcc * (1 - alpha);
			//std::cout << "FPS: " << (1.0 / dtAcc) << std::endl;
			std::cout << "x: " << m_scaleX << ", y: " << m_scaleY << "\n";
		}

		// Draw result
		/*for (int i = 0; i < pRectNum * pRectNum; ++i)
			cv::rectangle(imGray, m_rects[i], 255);//*/ // To draw each rect individually
		cv::rectangle(imGray, cv::Rect(m_left, m_top, (m_centerX - m_left) * 2, (m_centerY - m_top) * 2), 255);

		// Show output
		cv::imshow("output", imGray);
		cv::waitKey(1);
		++curFrame;
	}

	delete[] m_rects;
	cv::waitKey(10000);
}