CorePlot - unable to zoom using 2 plot spaces - zooming

I have 2 scatter plots in a single plot. Both the plots have the same x-axis but the y scale is different. So I have created a new plot space.
CPTGraph *graph = self.hostView.hostedGraph;
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) graph.defaultPlotSpace;
CPTXYPlotSpace *newPlotSpace = (CPTXYPlotSpace *) graph.newPlotSpace;
newPlotSpace.identifier = #"Fund PlotSpace";
[graph addPlotSpace:newPlotSpace];
// 2 - Create the two plots
CPTScatterPlot *aaplPlot = [[CPTScatterPlot alloc] init];
aaplPlot.delegate = self;
[graph addPlot:aaplPlot toPlotSpace:plotSpace];
CPTScatterPlot *fdPlot = [[CPTScatterPlot alloc] init];
fundingPlot.delegate = self;
[graph addPlot:fdPlot toPlotSpace:newPlotSpace];
I also have enabled user interaction
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) graph.defaultPlotSpace;
plotSpace.allowsUserInteraction = YES;
CPTXYPlotSpace *newPlotSpace = (CPTXYPlotSpace *) graph.newPlotSpace;
newPlotSpace.allowsUserInteraction = YES;
I have also done this
self.hostView = [(CPTGraphHostingView *) [CPTGraphHostingView alloc] initWithFrame:self.view.bounds];
self.hostView.allowPinchScaling = YES;
[self.view addSubview:self.hostView];
But the second plot does not zoom. I am unable to understand why.
Edit
Here is my full code

You're creating two new plot spaces but only adding one to the graph. The one with user interaction enabled in -configureGraph is different from the one created in -configurePlots and added to the graph.
The -newPlotSpace method creates a new plot space object for you. In -configureGraph, give it an identifier and add it to the graph (move those lines from -configurePlots). When you need to refer to it later (e.g., in -configurePlots), do this:
CPTXYPlotSpace *newPlotSpace = (CPTXYPlotSpace *)[graph plotSpaceWithIdentifier:#"Fd Plot Space"];

Related

When I use image encoder of CLIP model and text encode of Roberta model, Topk of text to image increased to 15 and then immediately decreased to 0.1

I am doing the task of pedestrian with text retrieval
I use the image encoder of the clip model to encode the image, and then use the Robert encoding language to finally calculate the cos similarity of two 768 dimensional vectors
And I only use the image encoder of CLIP with the projector removed as image encoder.
I replaced the text encoder and image encoder on the original frame, and the result of the original frame is reasonable.
Topk of text to image in new encoder increased to 15 and then immediately decreased to 0.1 in 9 epoch, while in the original frame, the topk can reach 58.
class RobertaTextEncode(nn. Module):
def_init_(self, args):
super(RobertaTextEncode, self)._init
self. out_channels = 768
self. args = args
self. in_palnes = 768
self. tokenizer = RobertaTokenizerFast. from_pretrained(' roberta-base')
self. text_encode = RobertaModel. from_pretrained(' roberta-base')
def forward(self, captions):
caption = [ caption.text for caption in captions]
device = torch. device("cuda:0"if torch. cuda. is_available() else "cpu")
tokenized = self. tokenizer. batch_encode_plus(caption, truncation=' longest_first', padding=' max_length', max_length=self. args. MODEL. text_length, add_special_tokens=True, return_tensors=' pt'). to(device)
encode_text = self. text_encode(** tokenized)
text_feature = encode_text. pooler_output # [b, 768]
return text_feature
def load_pretrain_model(model_path):
from . clip import clip
url = clip._MODELS[ model_path]
model_path = clip._download(url)
try:
model = torch. jit. load(model_path, map_location="cpu"). eval()
state_dict=None
except
RuntimeError: state_dict = torch. load(model_path, map_location="cpu")
h_resolution = int((224-32)//32+1)
w_resolution = int((224-32)//32+1)
model = clip. build_model(state_dict or model. state_dictC), h_resolution, w_resolution, 32)
return model
class clipImageEncode(nn.Module):
def __init__(self, cfg):
clip_model = load_pretrain_model('ViT-B/32)
clip_model.to('cuda')
self.image_encode = clip.model.encode_image
def forward(self, x):
visual_feat = self.image_encode(x)
return visual_feat
I want to know why. I would appreciate it if you could provide suggestions.

Bullet physics - sphere doesn't bounce

I'm playing around with Bullet, I have a ground-floor and a ball, and I want the ball to fall and bounce on the ground. However this doesn't happen, even with very high values of m_restitution, which is supposed to regulate the bounciness.
Any clue why this is happening? This is torturing me for some hours now with no luck.
btBroadphaseInterface* broadphase = new btDbvtBroadphase();
btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver;
dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration);
dynamicsWorld->setGravity(btVector3(0,+9.8,0)); // GLWidget - y axis points downwards !!!
/////////////////////////////////////////////////////////////////////////////
//// Ground ///////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
btDefaultMotionState* groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1), btVector3(0,0,0)));
btRigidBody::btRigidBodyConstructionInfo groundRigidBodyCI(0, groundMotionState, groundShape, btVector3(0,0,0));
groundRigidBodyCI.m_restitution = 1.0f;
groundRigidBodyCI.m_friction = 3.0f;
groundRigidBodyCI.m_rollingFriction = 3.0f;
groundRigidBodyCI.m_mass = 0.0f;
btRigidBody* groundRigidBody = new btRigidBody(groundRigidBodyCI);
dynamicsWorld->addRigidBody(groundRigidBody);
/////////////////////////////////////////////////////////////////////////////
//// Ball /////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
btDefaultMotionState* ballMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1), btVector3(0,-100,0)));
btScalar ballMass = 1;
btVector3 ballInertia;//(0,0,0);
ballShape->calculateLocalInertia(ballMass, ballInertia);
btRigidBody::btRigidBodyConstructionInfo ballRigidBodyCI(ballMass, ballMotionState, ballShape, ballInertia);
groundRigidBodyCI.m_restitution = 1.0f;
ballRigidBodyCI.m_friction = 1.0f;
ballRigidBodyCI.m_rollingFriction = 1.0f;
btRigidBody* ballRigidBody = new btRigidBody(ballRigidBodyCI);
dynamicsWorld->addRigidBody(ballRigidBody);
//Without the next it doesn't bounce at all
//With it, it bounces just a TINY little bit
dynamicsWorld->getSolverInfo().m_splitImpulse = false;
OK, the above code should work in theory, but I'm not sure why it doesn't work.
As said, the property that regulates bounciness is m_restitution. This can be set in two ways. The first way is noted in the question-post. The other way is the following:
groundRigidBody->setRestitution(1.0);
ballRigidBody->setRestitution(1.0);
...and it works. Based on what I read on the net (e.g. here), both ways should be fine, but in my case it works only with the second way. I'm using bullet-2.82-r2704 on Ubuntu.
This happens only with the m_restitution property, All the other properties are set fine in the way of my question-post.
Plus, the line dynamicsWorld->getSolverInfo().m_splitImpulse = false; is not needed any more.

What is the proper way to add MANY images to WP8 map?

In building a program that displays a map, I have two sliders:
that changes the map's pitch
that rotates the map's heading
And, two Buttons that change the Zoom_Level of the map
I have close to 200 images that need to be displayed on the map at any given time based on the zoom level. (each one is click-able)
With so many Images, I'm getting an:
"A first chance exception of type 'System.OutOfMemoryException' occurred in System.Windows.ni.dll"
thrown.
Many of these Images are the same - just displayed in different places. I find it very inefficient that I need to initialize each different Image separately and place it inside it's own MapOverlay instead of referencing a globally constructed Image and referencing it when I need it. (there is also a problem with Clearing the Map.Layers when the Images are defined globally).
Is there a better way to add many Images to a map?
After I hit about 50 Images I get the OutOfMemoryException (the Images need to be defined separately so that they are square in dimension for the rotating to work properly).
Does it matter how the Images are added to the Project/App ("Build Action" or the "Copy to Output Directory")? Would it be better to have them in Isolated Storage? Would this make a difference?
Here is the code I'm currently using to add Images:
MapLayer pinLayerZoom12 = new MapLayer();
MapOverlay pinOverlay = new MapOverlay();
// Add the location of the Pushpin using latitude and longitude.
pinOverlay.GeoCoordinate = new GeoCoordinate(49.33783000, -0.45215600);
Image pinOverlayImage = new Image();
pinOverlayImage.Source = new BitmapImage(new Uri("images/Hedgehog.png", UriKind.Relative));
pinOverlay.Content = pinOverlayImage;
pinOverlay.PositionOrigin = new Point(0.0, 0.0);
pinOverlayImage.Opacity = 0.8;
pinOverlayImage.Height = 10;
pinOverlayImage.Width = 10;
pinOverlayImage.Tap += pinOverlayImage_Tap;
pinLayerZoom12.Add(pinOverlay);
MapOverlay pinOverlay2 = new MapOverlay();
// Add the location of the Pushpin using latitude and longitude.,
pinOverlay2.GeoCoordinate = new GeoCoordinate(49.33783000, -0.44547083);
Image pinOverlay2Image = new Image();
pinOverlay2Image.Source = new BitmapImage(new Uri("images/Hedgehog.png", UriKind.Relative));
pinOverlay2.Content = pinOverlay2Image;
pinOverlay2.PositionOrigin = new Point(0.0, 0.0);
pinOverlay2Image.Opacity = 0.8;
pinOverlay2Image.Height = 10;
pinOverlay2Image.Width = 10;
pinOverlayImage.Tap += pinOverlayImage2_Tap;
pinLayerZoom12.Add(pinOverlay2);
// Add the layer to the map
map1.Layers.Add(pinLayerZoom12);
Thank you for any help you can give me!

I want to create a animation on google map,move from one location to another

i know the different locations' gps ,how i could create this animation?and i try to convert the gps to offset ,but i failed.so ,who could give me a point to solve the problem,thanks
GMSPolyline *polyline = [[GMSPolyline alloc] init];
GMSMutablePath *path = [GMSMutablePath path];
[path addCoordinate:kSanLiTun];
[path addCoordinate:kLongZe];
[path addCoordinate:kJinTai];
polyline.path = path;
polyline.strokeColor = [UIColor redColor];
polyline.strokeWidth = 2.f;
polyline.zIndex = 15; // above the larger geodesic line
polyline.map = self.mapView;
this code to draw three lines from location.i want to create animation could make a picture move on the line

How do i calculate an objects scale using a perspective projection matrix?

Im currently building a little 3D particle engine in flash the uses sprites.
to set the position of each sprite I am using the projectVector function below. (the viewTransform matrix is the particles world matrix concatenated with a perspective projection matrix)
var projectedPoint:Vector3D = Utils3D.projectVector(viewTransform, point);
sprite.x = projectedPoint.x;
sprite.y = projectedPoint.y;
this works really well an places the sprites exactly where they should be :D
The problem I am having is trying to figure out how to calculate the scale of the each particle based on is distance from the camera..
sprite.scaleX = sprite.scaleY = ??
If I wasn't using a perspective projection matrix I would usually do something like this..
var scaleRatio:Number = (focus * zoom)/(focus + particle.globalz);
particle.depth = scaleRatio;
sprite.x = particle.globalx * scaleRatio;
sprite.y = particle.globaly * scaleRatio;
// set scale..
sprite.scaleX = sprite.scaleY = scaleRatio;
If there is anyone out there able to show me how to calculate the "scaleRatio" using a perspective projection matrix that would be ace
thanks!
I'm sure there's a more succinct way to do this, but since you already know how to project a point, you could do this:
var tl:Point = sprite.getRect(sprite.parent).topLeft;
var br:Point = sprite.getRect(sprite.parent).bottomRight;
var projectedTL:Point = Utils3D.projectVector(viewTransform, tl);
var projectedBR:Point = Utils3D.projectVector(viewTransform, br);
trace("projected width = "+(projectedBR.x - projectedTL.x));
trace("projected height = "+(projectedBR.y - projectedTL.y));