custom cluster theme when high quantities of objects - here-api

Based on Example
https://developer.here.com/api-explorer/maps-js/clustering/custom-cluster-theme
loaded with 15000 objects from the json file.
The cluster is created by default 2 seconds, and drawn on the map. The custom cluster theme creates a cluster of long and sent many requests:
http://savepic.su/5817768.png
I think that the use of a user cluster in large volumes of data is not possible, is it true?

In general this should be an issue, unless there there are lot of event listeners created which are not disposed of. Can you share an example where you face the issue ?
I think the issue is caused by creating a lot of H.map.Icon in the custom theme, you basically need only 4 Icons which can be reused. Create something like follows with a global array clusterMarkers:
for (var i = 0; i < 4; i++) {
var diameter = 50;
switch( i ){
case 0 :
diameter = 50;
break;
case 1:
diameter = 20;
break;
case 2:
diameter = 12;
break;
case 3:
diameter = 10;
break;
};
var clusterMarker = new H.map.Icon(
clusterSvg
, {
size: {w: diameter, h: diameter},
anchor: {x: diameter/2, y: diameter/2}
}
);
clusterMarkers[i]=clusterMarker;
}
then in the theme
switch( weight ){
case weight < 10:
i=3;
break;
case weight < 100:
i=2;
break;
case weight < 1000:
i=1;
break;
case weight < 10000:
i=0;
break;
};
var clusterMarker = new H.map.Marker(cluster.getPosition(), {
min: cluster.getMinZoom(),
max : cluster.getMaxZoom(),
icon: clusterMarkers[i],
});

Related

How to use minimax alalgorithm without recursion?

I'm developing a program that people can play "tic tac toe" with a computer.
I choose structured text as my develop language, but it doesn't have recursion, so I have to develop it without recursion.
As the result, I decide to use the stack to instead, but I don't know how to change recursion into the stack.
I try to use stack like BFS, and also I wanna that minimax can make the best move.
I don't know Structured Text, but maybe it helps to see a solution in another language.
You need a stack with moves, so that when backtracking, you know from where to start to search for a next, alternative move for it.
You also need a stack of scores, so you know the best score so far at every depth of the minimax search tree.
The two stacks could be combined into one stack when you can store the two data in one structure to be placed on the single stack. But in the below implementation in JavaScript I have tried to keep the data structures as simple as possible and used two stacks (fix-sized arrays with a separate size variable). All variables are declared at the top of the functions (as in Structured Text), and return statements are always at the end of the function bodies (since there is no return statement in Structured Text).
function gameWon(board) {
/* Looks at all possible lines of 3,
* to see if they are occupied by three of the same symbols
* board: is a 1D array with 9 integers:
* 1 = "X" (first player), 0 = free, 1 = "O"
* Returns boolean.
*/
let value;
let i;
// In Structured Text you'd not have gameWonReturn,
// as you would use `gameWon` instead for returning a value
let gameWonReturn = false;
for (i = 0; i < 3; i++) {
value = board[i*3];
if (value != 0 && value == board[i*3+1] && value == board[i*3+2]) {
gameWonReturn = true;
break;
}
value = board[i];
if (value != 0 && value == board[i+3] && value == board[i+6]) {
gameWonReturn = true;
break;
}
if (value != 0 && value == board[4] && value == board[8-i]) {
gameWonReturn = true;
break;
}
}
return gameWonReturn;
}
function play(board, moveStack, moveCount, move) {
let playReturn;
// Derive played symbol from number of moves played
board[move] = 1 - (moveCount % 2) * 2; // Use MOD operator. Result is 1 or -1
moveStack[moveCount] = move; // Log move in stack
playReturn = moveCount + 1;
return playReturn;
}
function minimax(board, moveStack, moveCount) {
const scoreStack = Array(10); // Array of signed integers
const originalMoveCount = moveCount;
let move; // -1..9
let score; // -10..10
let player; // -1 or 1
let minimaxReturn = -1; // -1..9
while (true) {
// Current player can be derived from the number of moves that were played
player = 1 - (moveCount % 2) * 2; // 1 = First, maximizing player. -1 = Second, minimizing player
// Check for game-over
if (gameWon(board)) { // Preceding move resulted in win for previous player
scoreStack[moveCount] = -(10 - moveCount) * player; // Earlier wins get greater score
} else if (moveCount == 9) { // It's a draw
scoreStack[moveCount] = 0;
} else {
moveStack[moveCount] = -1; // Prepare for iterating moves for current player
scoreStack[moveCount] = -player * 10; // Initialize with worst possible score for current player
moveCount++;
}
do { // Repeat:
moveCount--;
if (moveCount < originalMoveCount) { // All done
break; // Exit point
}
// Look for a next, valid move
move = moveStack[moveCount];
if (move >= 0) { // Was a valid move: derive score from deeper results
score = scoreStack[moveCount + 1]; // Best score opponent can get
if ((board[move] == 1) == (score > scoreStack[moveCount])) { // Improvement
scoreStack[moveCount] = score;
if (moveCount == originalMoveCount) {
minimaxReturn = move; // For now this is a best move...
}
}
// Take back move
board[move] = 0;
}
// Look for next valid move
do {
move++;
} while (move < 9 && board[move] != 0) // Occupied
} while (move == 9); // Backtrack (i.e. repeat loop) when all moves were tried
if (moveCount < originalMoveCount) { // All done
break; // Exit point
}
// Play move
moveCount = play(board, moveStack, moveCount, move);
}
return minimaxReturn;
}
function main() {
const board = Array(9).fill(0); // An empty 3x3 board as 1 dimensional array
const moveStack = Array(10); // History of played moves (indices in board)
let moveCount = 0; // Number of moves played
let bestMove;
/* Demo:
* Play moves to arrive at this board:
*
* X | O |
* ---+---+---
* O | |
* ---+---+---
* X | |
*/
moveCount = play(board, moveStack, moveCount, 0); // Play X in top-left
moveCount = play(board, moveStack, moveCount, 1); // Play O next to it
moveCount = play(board, moveStack, moveCount, 6); // Play X in bottom-left
moveCount = play(board, moveStack, moveCount, 3); // Play O in middle row
// Run minimax for suggesting where to play an "X":
bestMove = minimax(board, moveStack, moveCount);
console.log(bestMove); // 4 (center of the board)
}
main();

abc PDF generate a blank page on IIS

I am creating an PDF from HTML using ABC PDF 8.0, it works well on my local end but generate a blank page on IIS, I already down grade IE, and provide the all permission to folder. When I tried to generate the PDF through any external link like Google.com it works perfectly. more over my link is accessible and there is no error on the page. please find below the code for your reference.
var url="test.com"
if (XSettings.InstallLicense(abcPDFkey))
{
using (Doc theDoc = new Doc())
{
//apply a rotation transform
double w = theDoc.MediaBox.Width;
double h = theDoc.MediaBox.Height;
double l = theDoc.MediaBox.Left;
double b = theDoc.MediaBox.Bottom;
theDoc.Transform.Rotate(90, l, b);
theDoc.Transform.Translate(w, 0);
// To fix time out
theDoc.HtmlOptions.RetryCount = 1;
theDoc.HtmlOptions.Timeout = 25000;
// rotate our rectangle
theDoc.Rect.Width = h;
theDoc.Rect.Height = w;
theDoc.HtmlOptions.Engine = EngineType.Gecko;
theDoc.HtmlOptions.ImageQuality = 60;
int theID;
theID = theDoc.AddImageUrl(url);
while (true)
{
theDoc.FrameRect();
if (!theDoc.Chainable(theID))
break;
theDoc.Page = theDoc.AddPage();
theID = theDoc.AddImageToChain(theID);
int NewtheID = theDoc.GetInfoInt(theDoc.Root, "Pages");
theDoc.SetInfo(NewtheID, "/Rotate", "90");
}
for (int i = 1; i <= theDoc.PageCount; i++)
{
theDoc.PageNumber = i;
theDoc.Flatten();
}
foreach (IndirectObject io in theDoc.ObjectSoup)
{
if (io is PixMap)
{
PixMap pm = (PixMap)io;
pm.Realize(); // eliminate indexed color images
pm.Resize(pm.Width / 6, pm.Height / 6);
}
}
theDoc.Save(System.Web.HttpContext.Current.Server.MapPath("PDFFileName"));
theDoc.Clear();
}
Please help, thanks
Ok, I figured out what was the issue.
First of all I define the relative path for all my Images, and secondly Our server have internal IP, I define the URL for internal IP instead of public domain. that fix my issue..
cheers !!

What will a break-statement do in Axapta?

I have 2 while loops, and in the second there is a break; (see the code below)
My question is: will the break cause a stop in the second loop or for the 2?
while select dirPartyRelationship
join dirPartyTable
where dirPartyTable.RecId == dirPartyRelationship.ChildParty
join dirPersonName
where dirPersonName.Person == dirPartyTable.RecId
{
while select checkDirRelationship
where checkDirRelationship.ChildParty == dirPartyRelationship.RecId
{
if (checkDirRelationship.RelationshipTypeId == _relationshipType)
{
break;
}
}...
The break will only break out of the current code block.
Create a job and use this sample code;
for(i=0; i<100; i++)
{
for(j=0; j<100; j++)
{
info(strfmt("inner loop count %1",j));
break;
}
info(strfmt("outer loop count %1",i));
}
You will see a quick example of j never getting over 0, but being printed 100 times.
Edit;
If you want to break out of the nested loop you could work around by declaring a boolean, maybe called breakAll, and setting breakAll to true before the break; line in the inner loop. In the outer loop check for breakAll like this;
for(i=0; i<100; i++)
{
for(j=0; j<100; j++)
{
info(strfmt("inner loop count %1",j));
if (somethingToCheck)
{
breakAll = true;
break;
}
}
info(strfmt("outer loop count %1",i));
if (breakAll)
{
break;
}
}

Negotiating an allocator between Directshow filters fails

I'm developing a custom Directshow source filter to provide decompressed video data to a rendering filter. I've used the PushSource sample provided by the Directshow SDK as a basis for my filter. I'm attempting to connect this to a VideoMixingRenderer9 filter.
When creating the graph I'm calling ConnectDirect():
HRESULT hr = mp_graph_builder->ConnectDirect(OutPin, InPin, &mediaType);
but during this call, calling SetProperties on the downstream filters allocator (in DecideBufferSize()), fails with D3DERR_INVALIDCALL (0x8876086c):
ALLOCATOR_PROPERTIES actual;
memset(&actual,0,sizeof(actual));
hr = pAlloc->SetProperties(pRequest, &actual);
If I let it try to use my allocator (the one provided by CBaseOutputPin) when setting the allocator on the downstream filter, this fails with E_FAIL (in CBaseOutputPin::DecideAllocator)
hr = pPin->NotifyAllocator(*ppAlloc, FALSE);
Any help would be much appreciated!
Thanks.
EDIT:
This is the media type provided by GetMediaType
VIDEOINFOHEADER *pvi = (VIDEOINFOHEADER*)pMediaType->AllocFormatBuffer(sizeof(VIDEOINFOHEADER));
if (pvi == 0)
return(E_OUTOFMEMORY);
ZeroMemory(pvi, pMediaType->cbFormat);
pvi->AvgTimePerFrame = m_rtFrameLength;
pMediaType->formattype = FORMAT_VideoInfo;
pMediaType->majortype = MEDIATYPE_Video;
pMediaType->subtype = MEDIASUBTYPE_RGB24;
pMediaType->bTemporalCompression = FALSE;
pMediaType->bFixedSizeSamples = TRUE;
pMediaType->formattype = FORMAT_VideoInfo;
pvi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
pvi->bmiHeader.biWidth = (640 / 128 + 1) * 128;
pvi->bmiHeader.biHeight = -480; // negative so top down..
pvi->bmiHeader.biPlanes = 1;
pvi->bmiHeader.biBitCount = 24;
pvi->bmiHeader.biCompression = NULL; // ok if rgb else use MAKEFOURCC(...)
pvi->bmiHeader.biSizeImage = GetBitmapSize(&pvi->bmiHeader);
pvi->bmiHeader.biClrImportant = 0;
pvi->bmiHeader.biClrUsed = 0; //Use max colour depth
pvi->bmiHeader.biXPelsPerMeter = 0;
pvi->bmiHeader.biYPelsPerMeter = 0;
SetRectEmpty(&(pvi->rcSource));
SetRectEmpty(&(pvi->rcTarget));
pvi->rcSource.bottom = 480;
pvi->rcSource.right = 640;
pvi->rcTarget.bottom = 480;
pvi->rcTarget.right = 640;
pMediaType->SetType(&MEDIATYPE_Video);
pMediaType->SetFormatType(&FORMAT_VideoInfo);
pMediaType->SetTemporalCompression(FALSE);
const GUID SubTypeGUID = GetBitmapSubtype(&pvi->bmiHeader);
pMediaType->SetSubtype(&SubTypeGUID);
pMediaType->SetSampleSize(pvi->bmiHeader.biSizeImage);
and DecideBufferSize where pAlloc->SetProperties is called
HRESULT CPushPinBitmap::DecideBufferSize(IMemAllocator *pAlloc, ALLOCATOR_PROPERTIES *pRequest) {
HRESULT hr;
CAutoLock cAutoLock(CBasePin::m_pLock);
CheckPointer(pAlloc, E_POINTER);
CheckPointer(pRequest, E_POINTER);
if (pRequest->cBuffers == 0) {
pRequest->cBuffers = 2;
}
pRequest->cbBuffer = 480 * ( (640 / 128 + 1) * 128 ) * 3;
ALLOCATOR_PROPERTIES actual;
memset(&actual,0,sizeof(actual));
hr = pAlloc->SetProperties(pRequest, &actual);
if (FAILED(hr)) {
return hr;
}
if (actual.cbBuffer < pRequest->cbBuffer) {
return E_FAIL;
}
return S_OK;
}
The constants are only temporary!
There is no way you can use your own allocator with VMR/EVR filters. They just insist on their own, which in turn is backed on DirectDraw/Direct3D surfaces.
To connect directly to VMR/EVR filters you need a different strategy. The allocator is always theirs. You need to support extended strides. See Handling Format Changes from the Video Renderer.

Can't get my object to point at the mouse

I'm using a combination of SDL and OpenGL in a sort of crash course project to teach myself how this all works. I'm really only interested in OpenGL as a way to use acceleration in 2D games so I just need this to work in a 2D plane.
I have been having a lot of problems today with my current issue, I would like an object to point towards the mouse while the mouse button is clicked and then of course stay pointing in that direction after the mouse is lifted.
void Square::handle_input() {
//If a key was pressed
if( event.type == SDL_KEYDOWN ) {
//Adjust the velocity
switch( event.key.keysym.sym ) {
case SDLK_UP: upUp = false; yVel = -1; break;
case SDLK_DOWN: downUp = false; yVel = 1; break;
case SDLK_LEFT: leftUp = false; xVel = -1; break;
case SDLK_RIGHT: rightUp = false; xVel = 1; break;
case SDLK_w: wUp = false; sAng = 1; break;
case SDLK_s: sUp = false; sAng = -1; break;
}
}
//If a key was released
else if( event.type == SDL_KEYUP ) {
//Adjust the velocity
switch( event.key.keysym.sym ) {
case SDLK_UP: upUp = true; yVel = 0; break;
case SDLK_DOWN: downUp = true; yVel = 0; break;
case SDLK_LEFT: leftUp = true; xVel = 0; break;
case SDLK_RIGHT: rightUp = true; xVel = 0; break;
case SDLK_w: wUp = true; sAng = 0; break;
case SDLK_s: sUp = true; sAng = 0; break;
}
}
//If a mouse button was pressed
if( event.type == SDL_MOUSEBUTTONDOWN ) {
switch ( event.type ) {
case SDL_MOUSEBUTTONDOWN: mouseUp = false; mousex == event.button.x; mousey == event.button.y; break;
case SDL_MOUSEBUTTONUP: mouseUp = true; break;
}
}
}
And then this is called at the end of my Object::Move call which also handles x and y translation
if (!mouseUp) {
xVect = mousex - x;
yVect = mousey - y;
radAng = atan2 ( mousey - y, mousex - x );
sAng = radAng * 180 / 3.1415926l;
}
Right now when I click the object turns and faces down to the bottom left but then no longer changes direction. I'd really appreciate any help I could get here. I'm guessing there might be an issue here with state versus polled events but from all the tutorials that I've been through I was pretty sure I had fixed that. I've just hit a wall and I need some advice!
I'm assuming that you want the object to keep pointing at the mouse's position while the mouse button is held. To fix this, you will have to update the mouse position every time the mouse is moved.
Add some code similar to this:
if( event.type == SDL_MOUSEMOVE ) {
// update the mouse position here using event.???.x / y
}
Note that I haven't got an SDL reference here, so I can't give you the exact members, but that should help.
NB: I would also guess that there would be problems with your button handling code. You have an if statement that checks for one value of event.type, but then inside its body you have a switch statement with two values. Only one of these values will ever be executed - you should probably think about just using 2 separate if statements for the button down / button up events.

Resources