Making cylindrical space in Repast Simphony? - repast-simphony

I am trying to model the interior of an epithelial space and am stuck on movement around the interior edges of a cylindrical space. Basically, I'm trying to implement StickyBorders and keep agents on those borders in a cylindrical space that I am creating.
Is there a way to use cylindrical coordinates in Repast Simphony? I found this example (https://www.researchgate.net/publication/259695792_An_Agent-Based_Model_of_Vascular_Disease_Remodeling_in_Pulmonary_Arterial_Hypertension) where they seem to have done something similar, but the paper doesn't explain methods in much depth, and I don't believe this is an example in the repast simphony models.
Currently, I have a class of epithelial cells that are set up to form a cylinder and other agents start just inside that cylinder. To move, they are choosing their most desired spot (similar to the Zombie code) then pointing to a new location in the direction of that desired location within one grid square of that original location. They check that new point before moving to it and make sure that there are at least two other epithelial cells in the immediate moore neighborhood, to ensure they stay against the wall.
GridPoint intendedpt = new GridPoint((int)Math.rint(alongX),(int)Math.rint(alongY),(int)Math.rint(alongZ));
GridCellNgh<EpithelialCell> nearEpithelium = new GridCellNgh<EpithelialCell>(mac_grid, intendedpt, EpithelialCell.class, 1,1,1);
List<GridCell<EpithelialCell>> EpiCells = nearEpithelium.getNeighborhood(false);
int nearbyEpiCellsCount=0;
for (GridCell<EpithelialCell> cell: EpiCells) {
nearbyEpiCellsCount++;
}
if (nearbyEpiCellsCount<2) {
System.out.println(this + " leaving epithelial wall /r");
RunEnvironment.getInstance().pauseRun();
//TODO: where to go if false
}
I am wondering if there is a way to either set the boundaries of the space to be a cylinder or to check which side of the agent is against the wall and restrict its movement in that direction.

The sticky border code (StickyBorders.java) essentially just checks if the point that the agent moves to is beyond any of the space's dimensions, and if so the point is clamped to that dimension. So, for example, if the space is 3x4 and an agent's movement would take it to 4,2, then that point becomes 3,2 and the agent is placed there. Can you do something like that in this case? If not, can you edit your question to explain why not and maybe that will help us understand better.

The approach we took in that model was to use a 3D grid space with custom borders and query methods. The space itself was still Cartesian - we just visualized it as a cylinder using custom display code. Using the Cartesian grid was an reasonable approximation for this application since the cell dimensions were significantly smaller that the vessel radius, so curvature effects were neglected. The boundary conditions on the vessel space were wrap around in the angular dimension, so that cells could move continuously around the circumference of the vessel, and the axial boundary conditions were also wrapped, as we assumed a long enough vessel length that this would be reasonable. The wall thickness dimension had hard boundaries at the basement membrane (y=0) and at the fluid interface (y=wall thickness).
Depending on which type of space you are using, you will need to implement a PointTranslator or GridPointTranslator that performs the border functions. If you want specific examples of the code I suggest you reach out to the author's directly.

Related

Index for trivial pursuit game's spaces

I'm trying to code a trivial pursuit game. I want to give an id for every space of the board in order to use them for the movements. I need to know for every space which is next to which/match with each other.
But because of the geometry of the board(extern circle + radii), I didn't find the right logic behind this.
I am thinking of an ID based on 7 numbers (for the 6 radii + the circle). For example :
//this is not my code, i'm just trying to show example of IDs
center = [0][0][0][0][0][0][-2]
one on the "2nd radius" = [0][3][0][0][0][0][-2]
one the circle and the "3rd radius" = [0][0][6][0][0][0][22]
one on the circle = [0][0][0][0][0][0][21]
I have no idea if it's gonna work or if it's optimal, i will try and see.
If some of you have any better idea for name the ID, i would be happy to listen to them.
Here is an image of the board.
enter image description here
Thank you for helping!
OK, seeems you are inventing some coordinate system for this wheel for easy addressing and easy transtions between cells. System with many indices looks too complex.
Perhaps two-index scheme would be appropriate. Resembles polar coordinates:
The first index 0..6 as distance from the center.
The second one 1..42 - angular position.
So center cell is A[0][0] (the second index is not defined, we can choose any)
It's neighbors are A[1][1], A[1][8], A[1][15] ..A[1][36] (marked with 1 at your picture)
Similar for the next cells at the rays A[2][1], A[2][8], A[2][15] ..A[2][36] and so on
Wheel cells are A[6][1], A[6][2]..A[6][42]
Now neighbor cells have coordinates where one index differs by 1 (except for central cell, extra case)
Is this scheme suitable?

Cocos2d / CCDrawNode - How to draw a line?

I see there is functionality to draw circles, polys, dot and segments. I dont see one for drawing an A-B line (with given thickness), like ccDrawLine() (which seems to be deprecated).
I need to draw a 'network' between connected nodes. I have the code to draw the network, however ccDrawLine doesn't seem to support aliasing or opacity, like CCDrawNode. It also, without manual intervention, doesn't seem to support batching.
Any suggetions? Would I need to do a load of maths to draw a 2 tri-poly rectangle at the right angle between points?
UPDATE:
Based on comments below... I have an idea on how to do a 'Line' 0,0 to 10,0 with thickness 2, I'd have to do a rect at {0,0.5}, {10,0.5}, {10,-0.5}, {0,-0.5}... I can work out the clockwise triangle points to make a polygon from that easily. I, therefore, could even do horiz/vert ones easily. But how do you do that between {4,5}, {10,7}? Would you do a normal rectangle and apply a transformation matrix to it? Or would you still precalculate each 4 points and then make 2 triangles from it?
UPDATE:
Maybe it'd be better to use a scaled "line" sprite?! Eg: https://stackoverflow.com/a/8760462/224707
UPDATE:
How about a Ribbon? Would that work? Eg: https://stackoverflow.com/a/8178729/224707
Not sure a Ribbon would work for a "network" of points though...
CLARIFICATION:
Imagine this image, but with straight lines and no intersections... Something like this:
(source: relenet.com)
UPDATE:
Apparantly, my post to the Forum did go though last night just before it went down... http://www.cocos2d-iphone.org/forum/topic/224498
A line is a segment. You can take it from here... ;)
Update:
CCDrawNode can draw segments. Segments are lines with defined start and end points.

The best way to change background color in image in Cocoa

Little description:
I get an image from my scanner using Capture Core Framework and background color is gray. So I want to do white background.
I'm looking for best way to remove this color. I looked at Image Core Filters. And as I understood I should use those ones, but I couldn't find included/ready filterfor this task. So, Do I have to write it myself?
It means to remove color I should write my own filter and apply it to my images? Right? Thank you.
UPD: I develop for Mac os
Why not just simply change the brightness of your image? If this gray background color value is fixed then you can increase the brightness a little bit, as a preprocess step, until you're satisfied.
A filter isn't quite the right tool for the job here. Filters apply a colour-shifting algorithm, pixel by pixel, to all of the pixels in an image.
This would be appropriate in your case if there was something completely unique about the pixels that you want to turn to white. For example, if the background you wish to eliminate was in a very narrow colour range that did not occur in any other part of the image. This is the technique used in greenscreen/bluescreen filming, which only works if that green or blue colour does not occur anywhere in the image regions you want to keep.
But - as you say in one of your comments - you cannot do this as that grey level you want to get rid of will not be unique to the background, so any filter you apply that would pick out those pixes may also affect pixels in the scanned subjectmatter.
What you really need is a way to select a region of interest and apply a filter to that region alone. You could use openCV for this. In fact it has a function that can achieve your result in one go:
http://docs.opencv.org/modules/imgproc/doc/miscellaneous_transformations.html?highlight=floodfill#int
floodFill(InputOutputArray image, //image to process
Point seedPoint, //starting pixel
Scalar newVal, //New value of the repainted domain pixels
Rect* rect, //optional output param (you won't need it)
Scalar loDiff, //max lower brightness/colour diff to select
Scalar upDiff, //max upper brightness/colour diff to select
int flags) //you want FLOODFILL_FIXED_RANGE
This function starts from a seedPoint, which should be any pixel that you can guarantee will be a part of the background grey you want to eliminate. (0,0) might work for you. It then interrogates neighbouring pixels, including them in the ROI array if they are sufficiently similar. The resulting array is a connected region. If your background grey uniformly falls between loDiff and upDiff - and your subject scan has a defined edge which does NOT fall into this range, you will get your result - selection and remapping of all background pixels to newVal (white).

connect line between two boxes avoiding passing others

I have several boxes (x,y,width,height) randomly scattered around, and some of them need to be linked from point (x1,y1) in box1 to point (x2,y2) in box2 by drawing a line. I am trying to figure a way to make such line avoid passing through any other boxes (other than box1 and box2) by drawing several straight interconnected lines to go around any box in the way (if it is not possible to go with one straight line). The problem is that I don't know an algorithm for such thing (let alone having a technical/common name for it). Would appreciate any help in the form of algorithm or expressed ideas.
Thanks
Assuming that the lines can't be diagonal, here's one simple way. It's based on BFS and will also find the shortest line connecting the points:
Just create a graph, containing one vertex for each point (x, y) and for each point the edges:
((x,y),(x+1,y)) ((x,y),(x-1,y)) ((x,y),(x,y+1)) ((x,y),(x,y-1))
But each of this edges must be present only if it doesn't overlap a box.
Now just do a plain BFS from point (x1,y1) to (x2,y2)
It's really easy to obtain also diagonal lines the same way but you will need 8 edges for each vertex, that are, in addition to the previouses 4:
((x,y),(x-1,y+1)) ((x,y),(x-1,y-1)) ((x,y),(x+1,y-1)) ((x,y),(x+1,y+1))
Still, each edge must be present only if it doesn't overlap a box.
EDIT
If you can't consider space divided into a grid, here's another possibility, it won't give you the very shortest path, though.
Create a graph, in which each box is a vertex and has an edge to any other box that can be reached without the line to overlap a third box. Now find the shortet path using dijkstra between box1 and box2 containing the two points.
Now consider each box to have a small countour that doesn't overlap any other box. This way you can link the entering and the exiting point of each box in the path found through dijistra, passing through the countour.
Put all (x,y) coords of the corners of the boxes in a set V
Add the start- and end coordinates to V.
Create a set of edges E connecting each corner that does not cross any box-side (except for the diagonals in the boxes).
How to check if a line crosses a box side can be done with this algorithm
Now use a path-finding algorithm of your choice, to find a path in the graph (V, E).
If you need a simple algorithm that finds the shortest path, just go with a BFS.
(This will produce a path that goes along the sides of some boxes. If this is undesirable, you could in step 1 put the points at some distance delta from the actual corners.)
If the edges may not be diagonal:
Create a large grid of lines that goes between the boxes.
Throw away the grid-edges that cross a box-side.
Find a path in the grid using a path-finding algorithm of your choice.

Projectile hit coordinates at the apex of its path

I have a projectile that I would like to pass through specific coordinates at the apex of its path. I have been using a superb equation that giogadi outlined here, by plugging in the velocity values it produces into chipmunk's cpBodyApplyImpulse function.
The equation has one drawback that I haven't been able to figure out. It only works when the coordinates that I want to hit have a y value higher than the cannon (where my projectile starts). This means that I can't shoot at a downward angle.
Can anybody help me find a suitable equation that works no matter where the target is in relation to the cannon?
As pointed out above, there isn't any way to make the apex be lower than the height of the cannon (without making gravity work backwards). However, it is possible to make the projectile pass through a point below the cannon; the equations are all here. The equation you need to solve is:
angle = arctan((v^2 [+-]sqrt(v^4 - g*(x^2+2*y*v^2)))/g*x)
where you choose a velocity and plug in the x and y positions of the target - assuming the cannon is at (0,0). The [+-] thing means that you can choose either root. If the argument to the square root function is negative (an imaginary root) you need a larger velocity. So, if you are "in range" you have two possible angles for any particular velocity (other than in the maximum range 45 degree case where the two roots should give the same answer).
I suspect one trajectory will tend to 'look' much more sensible than the other, but that's something to play around with once you have something working. You may want to stick with the apex grazing code for the cases where the target is above the cannon.