Load volume in xtk without initializing a renderer - xtk

I'm using xtk to read remote NIfTI volumes into an application. My sole objective is to obtain a volume object so I can extract its data; I don't need to render anything. The examples I've seen all initialize a renderer and attach a volume before accessing its contents. E.g. (from http://jsfiddle.net/QxMSt/5/):
var r = new X.renderer3D();
r.init();
var v = new X.volume();
v.file = 'http://www.cogitatum.org/mprage003.nii.gz';
r.add(v);
r.render();
r.onShowtime = function() {
r.destroy();
// get the image data
var data = v.image;
}
This works very nicely, but I'd rather not have to go to the trouble of creating a renderer for nothing, and would also prefer not to require WebGL support. Is there any way to initialize the volume and access its properties without rendering? I've looked through the codebase but don't see any place an onLoad() event or comparable is fired at the moment, though X.loader clearly tracks loading completion internally. It looks as though setting the volume's file property is sufficient to trigger volume loading, but I don't see any way to pass a callback function that gets triggered on completion. Any suggestions?

Unfortunately this is currently the only solution. The file loading starts when adding the object to the renderer.
To avoid the WebGL requirement, just use a X.renderer2D.
A separate and generic i/o library externally from XTK is planned and should be available in the next couple of weeks.

I also need just the volume information, so what I did is:
var filename = "../data/data.nrrd";
var volume = new X.volume();
volume.file = filename;
var request = new XMLHttpRequest();
request.open("GET", filename, true);
request.responseType = 'arraybuffer';
request.onload=function()
{
var _data = request.response;
volume._filedata = _data;
var loader = new X.loader();
loader.load(volume, volume);
loader.complete = function()
{
volumeImage = volume.image;
// process volumeImage
}
}
request.send(null);

Related

Return Item's Presentation Details In Rest API programatically

I have a Rest API which needs to return an item's presentation details.
I tried this line of code, but Sitecore.Context.Device is null, since this is a rest API call.
LayoutItem layoutItem = item.Visualization.GetLayout(Sitecore.Context.Device);
Update: I tried moving this code to when I index my data (hoping to read the value and write it to Solr), but I am facing the same issue.
How would I go about doing this?
The renderings are added per "device" in Sitecore, but in most cases nowadays, there's only one device. Depending on how you route your API endpoint etc., the device may not be resolved automatically. If you know you only have one device, you could pick the first device, or provide the device as a parameter. Then you can use a device switcher in case you need to call other Sitecore methods that requires a device to be set. For example like this:
var deviceName = "Default"; // The default device. Modify according to needs
var deviceItem = item.Database.Resources.Devices.GetAll().First(d => string.Equals(d.Name, deviceName, StringComparison.OrdinalIgnoreCase))
using (new DeviceSwitcher(deviceItem))
{
...
}

How to use #FetchRequest data in Provider struct in iOS 14 Widget [duplicate]

I want to display data fetched from Core Data in a widget. But #FetchRequest doesn’t work on widgets.
As I understand, we have to create an app group and make a shared persistent container.
What I want to know is how to read (fetch) data on widgets from that shared persistent container or simply, how to display data fetched from Core Data in widgets.
First you need to create an AppGroup which will be used to create a Core Data Persistent Container (here is a good explanation how to do it)
Then you need to create your own CoreData stack (an example can be found when you create a new empty project with CoreData enabled).
Accessing Core Data Stack in MVVM application
Assuming you have already created your Core Data model (here called DataModel), you now need to set the container url to your custom shared container location:
Share data between main App and Widget in SwiftUI for iOS 14
let containerURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: <your_app_group>)!
let storeURL = containerURL.appendingPathComponent("DataModel.sqlite")
let description = NSPersistentStoreDescription(url: storeURL)
let container = NSPersistentContainer(name: "DataModel")
container.persistentStoreDescriptions = [description]
container.loadPersistentStores { ... }
Now you can get the managedObjectContext from your shared Persistent Container:
let moc = CoreDataStack.shared.managedObjectContext
and perform a fetch request with it (more information here)
let predicate = NSPredicate(format: "attribute1 == %#", "test")
let request = NSFetchRequest<SomeItem>(entityName: "SomeItem")
let result = try moc.fetch(request)
Apart from all the links above I recommend you also read this tutorial about Core Data:
Core Data with SwiftUI Tutorial: Getting Started
Here is a GitHub repository with different Widget examples including the Core Data Widget.
For people who did all the work above, and finally can get the connection to your Core Data (e.g. you can get the count of request), but can't fetch the request, is mostly because that the entity you're fetching contains transformable type, and for some reason this error occurred: Cannot decode object of class, try fix this.

Tiles not shown on cesium

I created a viewer and added a customized layer (which is provided by myself). I am using the akka map server. My problem is that my map tiles are not displayed, although I can see from the console that cesium has loaded the tiles.
The code looks like this:
var viewer = new Cesium.Viewer("cesiumContainer");
var layers = viewer.scene.imageryLayers;
var through = layers.addImageryProvider(new Cesium.UrlTemplateImageryProvider({
url : 'http://my_ip:8777/modis/ndvi/{z}/{x}/{y}.png',
format: "image/png"
}));
through.alpha = 0.5;
If I change the url to another map such as blackmarble, it loads correctly
(i.e. the tiles are displayed, but the position y must be changed to reverseY). Does any body know why my map can't be loaded on the cesium?
I had found the key point.
Cesium must add CORS add the TMS which you want add it to your layers.
So just add the akka CORS suport,then everything will ok!

Google Glass GDK: updating LiveCards (RemoteViews)

Having Problem updating a LiveCard using remote views. I am publishing using this code. I am assuming that you can get the LiveCard using TimelineManager.getLiveCard(id) and then publishing again. The result I get is two LiveCards. I am using the same id both times I publish the cards.
As a workaround I am unpublishing and then publishing, but that is not a smooth transition as it shows the 'Okay Glass' between.
private void publishCard(Context context) {
String cardId = "myCard";
mLiveCard = tm.getLiveCard(cardId);
mLiveCard.setNonSilent(true);
RemoteViews rv = new RemoteViews(context.getPackageName(),
R.layout.activity_vitals_glass);
rv = updateViews(rv, pr);
mLiveCard.setViews(rv);
Intent intent = new Intent(context, MenuActivity.class);
mLiveCard.setAction(PendingIntent.getActivity(context, 0, intent, 0));
mLiveCard.publish();
}
The updateViews() method just sets textviews on the remote view. What is the proper way to update a LiveCard with RemoteViews?
getLiveCard creates a new live card, so you should only call it once when your service is started and cache the LiveCard instance that you receive.
You can also cache the RemoteViews instance at the same time. To update the card after it's published, you'll just need to manually call setViews on the LiveCard again after you call any of the RemoteViews setters.

Trouble replicating demo with my own data. .vtk [

I am trying to replicate this example with my own data.
window.onload = function() {
// create and initialize a 3D renderer
var r = new X.renderer3D();
r.init();
// create a mesh and associate it to the VTK Point Data
var p = new X.mesh();
p.file = 'http://x.babymri.org/?pits.vtk';
I understand you cannot simply point to the local .vtk file. I have read that webgl required the file to be served, so I am now correctly serving it from localhost.
I have placed exactly the same data (as served to the above example) locally and saved it in the file DATA.vtk.
I have modified MIME types inside IIS manager so that .vtk is text/html and when you point to either the raw data's url (in the original example) or my localhost data, they look exactly the same.
However, it still does not work. Specifically, this is my error:
Uncaught TypeError: Cannot read property 'length' of null xtk.js:179
Here is a picture of what I'm talking about...