Maya API: how to change UI Time Working Unit - c++

I need to change the time working unit of Maya using the API.
(see Window->Settings/Preferences->Preferences->Settings->Working Units->Time)
So I do:
MTime::Unit mayaTime = MTime::k120FP;
status = MTime::setUIUnit(mayaTime);
[import some animated data]
// For debug
MTime::Unit tm = MTime::uiUnit();
tm is k120FPS so it is ok. Also, animated data are ok. BUT, when I open the GUI, time working units is still the default one...
The documentation says:
"MTime::setUIUnit: Set the unit system to be used by the user in the UI. After the successful completion of this method, Maya's timeslider will be displaying frames in the specified units."
Do you see what I did wrong here?
Thanks for any help.

Try setting the optionVar "workingUnitTime".

Related

DCMTK Understand the "DIMSE No valid Presentation Context ID" error

I'm currently developing a simple application for querying/retrieving data on a PACS. I use DCMTK for this purpose, and a DCM4CHEE PACS as test server.
My goal is to implement simple C-FIND queries, and a C-MOVE retrieving system (coupled with a custom SCP to actually download the data).
To do so, I've created a CustomSCU class, that inherits the DCMTK DcmSCU class.
I first implemented a C-ECHO message, that worked great.
Then, I tried to implement C-FIND requesting, but I got the error "DIMSE No valid Presentation Context ID" (more on that in the next paragraph) from my application, but no other log from DCM4CHEE. I've then used the command tool findscu (from dcmtk) to see if there was some configuration issue but the tool just worked fine. So in order to implement my C-FIND request, I've read the source of findscu (here) and adapted it in my code (meaning that i'm not using DcmSCU::sendCFindRequest but the class DcmFindSU).
But now, i'm facing the same problem with C-MOVE request. My code is pretty straight-forward :
//transfer syntaxes
OFList<OFString> ts;
ts.push_back(UID_LittleEndianExplicitTransferSyntax);
ts.push_back(UID_BigEndianExplicitTransferSyntax);
ts.push_back(UID_LittleEndianImplicitTransferSyntax);
//sop class
OFString pc = UID_MOVEPatientRootQueryRetrieveInformationModel;
addPresentationContext(pc, ts);
DcmDataset query;
query.putAndInsertOFStringArray(DCM_QueryRetrieveLevel, "PATIENT");
query.putAndInsertOFStringArray(DCM_PatientID, <ThePatientId>);
OFCondition condition = sendMOVERequest(findPresentationContextID(pc, ""), getAETitle(), &query, nullptr);
return condition.good();
I've also tried using UID_MOVEStudyRootQueryRetrieveInformationModel instead of UID_MOVEPatientRootQueryRetrieveInformationModel, with the same result : my application shows the error
DIMSE No valid Presentation Context ID
As I understand, a presentation context is concatenation of one or more transfer syntax and one SOP class. I read that the problem could come from the PACS that won't accept my presentation contexts. To be sure, I used the movescu tool (from DCMTK). It worked, and I saw this in the logs from de server DCM4CHEE :
received AAssociatedRQ
pc-1 : as=<numbers>/Patient Root Q/R InfoModel = FIND
ts=<numbers>/Explicit VR Little Endian
ts=<numbers>/Explicit VR Big Endian
ts=<numbers>/Implicit VR Little Endian
That means that the movescu tool does a find before attempting an actual move ?
Therefore, I changed my application context creation with :
OFList<OFString> ts;
ts.push_back(UID_LittleEndianExplicitTransferSyntax);
ts.push_back(UID_BigEndianExplicitTransferSyntax);
ts.push_back(UID_LittleEndianImplicitTransferSyntax);
OFString pc1 = UID_FINDPatientRootQueryRetrieveInformationModel;
OFString pc = UID_MOVEPatientRootQueryRetrieveInformationModel;
addPresentationContext(pc1, ts);
addPresentationContext(pc, ts);
(also tried study root)
But this didn't do the trick.
The problem seems to lie on the client side, as findPresentationContextID(pc, ""); alwasy return 0, no matter what.
I don't feel like it's possible to adapt the code of the movescu tool, as it appears to be very complex and not adequat for simple retrieve operations.
I don't know what to try. I hope someone can help me understand what's going on. That's the last part of my application, as the storage SCP already works.
Regards
It looks like you are not negotiating the association with the PACS.
After adding the presentation contexts and before sending any command, the SCU must connect to the PACS and negotiate the PresentationContexts with DcmSCU::initNetwork and then DcmSCU::negotiateAssociation.

Jupyter Ipywidgets behave Inconsistently when displaying and refreshing

I've made a jupyter notebook that displays some graphs and dataframes. I can then change the widget values to refresh the dataframes and graphs.
I'm running into two problems:
Every time I run the book for the first time after opening Jupyter notebook, I get this:
Yet when I run all cells again, I get the desired output:
Every time I use the widgets and make a change, the notebook eventually refreshes correctly, but for some reason it continually outputs the top few graphs, seems to clear the output, then show them again, then clear output, and after a few iterations of this, is able to display everything. Here is my event handler:
def handle_submit(sender):
clear_output(wait=True)
start = w.slider_start.value.strftime('%Y-%m-%d')
end = w.slider_end.value.strftime('%Y-%m-%d')
zval = z.value
yval = y.value
xval = x.value
df_dlm,df_dgo,df_stats = show_stats(zval,yval,xval,start,end)
df_e = show_stats_exp(zval,yval,xval,start,end)
display_dataframe(df_stats)
plot_lines_e(df_e)
dfx = prepare_data(df_dlm,df_dgo)
plot_lines(dfx)
plot_scatter(dfx)
where the display_dataframe, plot_lines, and plot_scatter functions all have a "display" type line in them to actually show the graph since %matplotlib inline does not play well with ipywidgets...feels like that has something to do with it, but not sure how to get around this.
FYI the graphs are done in Bokeh, certain dataframes are plotted at matplotlib objects.
Thanks for your help!
That warning is just a bug that should be fixed in the next version of ipywidgets I believe. In the mean time the only thing that you can do is wait ~10-20 seconds after loading or reloading the notebook and the "trusted" box appears in the right hand corner as picture below;
Try executing all of your code only after you see that box come up.

mongoDB cursor timeout in C++

I get the following error using mongoDB through its C++ API on a 64-bit installation:
getMore: cursor didn't exist on server, possible restart or timeout?
The code snippet where the error is located is the following:
std::auto_ptr<mongo::DBClientCursor> cursor =
connection.query("database.collection", mongo::BSONObj());
while (cursor->more()) {
// Do stuff
// Update contents of fields
connection.update(...);
}
What the code simply does is updating the contents of each document's fields based on a specific data structure.
The code has been tested with a small data set, and it works perfectly fine, so I assume this is not a coding error, but rather a database-side error that is related to the size of the final data set.
My error looks similar to this bug report. The solution that is proposed there is to set the cursor to have no timeout, but there is no such function for the C++ API, although it seems to exist for other languages.
Any suggestions would be much appreciated.

Django share unpicklable objects between requests

I am currently working on a Django project that will hopefully make some transformations to videofiles thru the web. To make the transformation to the videos, I am using opencv's python API and I am also uing Dajax to perform ajax requests.
In the ajax requests file i have the following code:
#dajaxice_register
def transform_and_show(request, filename, folder, frame_count, img_number):
detector = Detector(filename) //Object which uses opencv API
dajax = Dajax()
generated_file = detector.detect_people_by_frame(folder, str(img_number))
dajax.assign('#video', 'src', '/media/generated'+folder+generated_file)
return dajax.json()
The idea is to tranform videos frame by frame and to display each transformed frame in the browser in an img tag giving the sensation to the user that he/she is watching the transformed video, so this method is called in a javascript loop.
The problem is that in this approach, the object "detector" is reinitialized in every iteration so it only generates the image corresponding to the first frame of the video. My idea was to workaround this issue by making "detector" persistent between requests so that the pointer to the next frame of the video wouldn't be set to 0 on every request.
The problem is that Dectector object is not picklable, meaning that it cannot be cached or saved to a session object.
Is there anything I can do to make it persistent between requests?
NOTE: I have considered using HTTP push approaches like APE or Orbit but since this is just an investigation project there is no real concern about performance.
Have you tried a module level variable to store the object?
Make "detector" a global at the file level.
detector = None
def transform():
global detector
if detector is None:
detector = Detector(filename)
file = detector.detect(....)

Accessing Firefox tab element in nsIWebProgressListener::OnStateChange using C++

I am developing extension for Firefox 3.0-3.5 versions using VS2008.
I want to set attribute to a tab once the document load request completes within that tab window.
So in OnStateChange method, I am checking for document load.
I have used STATE_STOP & STATE_IS_DOCUMENT for it.
I want to determine which tab window has been associated with particular document request.
I have valid DOM Document pointer got from nsIWebProgress *aWebProgress which is 1st input
parameter of OnStateChange.
if ((aStateFlags & STATE_STOP) && (aStateFlags & STATE_IS_DOCUMENT))
{
nsCOMPtr<nsIDOMWindow> domwin;
nsCOMPtr<nsIDOMDocument> domDoc;
aWebProgress->GetDOMWindow(getter_AddRefs(domwin));
domwin->GetDocument(getter_AddRefs(domDoc));
}
I have tried to get nsIDOMDocumentXBL pointer by QIing nsIDOMDocument pointer(domDoc in my example) but it fails with Error code 0x80004002 (2147500034) i.e.NS_ERROR_NO_INTERFACE.
How do I get the tab element corresponding to document load request.
Could any one please help me?
Thanks in Advance,
Vaibhav D. Gade.
IF I understood the question correctly and you want a for a content window, you probably need https://developer.mozilla.org/en/Working_with_windows_in_chrome_code#Accessing_the_elements_of_the_top-level_document_from_a_child_window to get the chrome window, then run the implementation of gBrowser.getBrowserForDocument in the chrome window.
You'd save yourself a lot of time if you stopped writing C++ and switched to JS for such things.